home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / vibutils.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  90.4 KB  |  4,047 lines  |  [TEXT/R*ch]

  1. /*   vibutils.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibutils.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.44 $
  33. *
  34. * File Description: 
  35. *       Vibrant miscellaneous functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49. #include <ncbiport.h>
  50.  
  51. #ifdef WIN_MAC
  52. #include <Printing.h>
  53. #include <Processes.h>
  54. #include <GestaltEqu.h>
  55. /*#include <Strings.h> */
  56. #endif
  57.  
  58. #ifdef WIN_MSWIN
  59. #include <commdlg.h>
  60. #endif
  61.  
  62. #ifdef WIN_MOTIF
  63. #include <Xm/FileSB.h>
  64. #ifdef OS_UNIX
  65. #include <unistd.h>
  66. #endif
  67. #ifdef OS_VMS
  68. #endif
  69. #endif
  70.  
  71. #ifdef WIN_MAC
  72. Nlm_Int2     Nlm_nextIdNumber = 2;
  73. #endif
  74. #ifdef WIN_MSWIN
  75. Nlm_Int2     Nlm_nextIdNumber = 102;
  76. #endif
  77. #ifdef WIN_MOTIF
  78. Nlm_Int2     Nlm_nextIdNumber = 1;
  79. #endif
  80.  
  81. Nlm_PoinT    Nlm_globalMouse;
  82. Nlm_PoinT    Nlm_localMouse;
  83.  
  84. Nlm_Int2     Nlm_hScrollBarHeight;
  85. Nlm_Int2     Nlm_vScrollBarWidth;
  86.  
  87. Nlm_Int2     Nlm_dialogTextHeight;
  88. Nlm_Int2     Nlm_popupMenuHeight;
  89.  
  90. Nlm_Char     Nlm_currentKey = '\0';
  91.  
  92. Nlm_Boolean  Nlm_cmmdKey = FALSE;
  93. Nlm_Boolean  Nlm_ctrlKey = FALSE;
  94. Nlm_Boolean  Nlm_optKey = FALSE;
  95. Nlm_Boolean  Nlm_shftKey = FALSE;
  96. Nlm_Boolean  Nlm_dblClick = FALSE;
  97.  
  98. static Nlm_WindoW       postWindow = NULL;
  99. static Nlm_PrompT       postPrompt = NULL;
  100.  
  101. static Nlm_Boolean      errorBoxUp;
  102. static Nlm_Int2         errorBoxRsult;
  103.  
  104. static Nlm_GraphiC      recentGraphic = NULL;
  105. static Nlm_GraphicData  recentGraphicData;
  106.  
  107. static Nlm_BoX          recentBox = NULL;
  108. static Nlm_BoxData      recentBoxData;
  109.  
  110. #ifdef WIN_MAC
  111. static THPrint   prHdl = NULL;
  112. static TPPrPort  prPort = NULL;
  113. static Nlm_Int2  prerr;
  114. static Nlm_Char  fileTypes [32] = {0};
  115. #endif
  116.  
  117. #ifdef WIN_MSWIN
  118. static Nlm_Boolean   abortPrint;
  119. static HDC           hPr = NULL;
  120. static Nlm_Int2      prerr;
  121. static int           vibrant_disabled = 0;
  122. static int           disabled_count = 0;
  123. static PRINTDLG      pd;
  124. static OPENFILENAME  ofn;
  125. #endif
  126.  
  127. #ifdef WIN_MOTIF
  128. static Widget       fileDialog = NULL;
  129. static Nlm_Boolean  fileBoxUp;
  130. static Nlm_Boolean  fileBoxRsult;
  131. static Nlm_Char     filePath [256];
  132. #endif
  133.  
  134. extern Nlm_Uint4 Nlm_StrngLen (Nlm_CharPtr string)
  135.  
  136. {
  137.   Nlm_Uint4  len;
  138.  
  139.   len = 0;
  140.   if (string != NULL) {
  141.     while (*string != '\0') {
  142.       string++;
  143.       len++;
  144.     }
  145.   }
  146.   return len;
  147. }
  148.  
  149. extern void Nlm_StrngCat (Nlm_CharPtr dest, Nlm_CharPtr source, Nlm_sizeT maxsize)
  150.  
  151. {
  152.   Nlm_Uint4  count;
  153.   Nlm_Uint4  i;
  154.  
  155.   if (dest != NULL && source != NULL && maxsize > 0) {
  156.     count = Nlm_StrngLen (source);
  157.     i = Nlm_StrngLen (dest);
  158.     if (count + i >= maxsize) {
  159.       count = maxsize - i - 1;
  160.     }
  161.     dest += i;
  162.     while (count > 0) {
  163.       *dest = *source;
  164.       dest++;
  165.       source++;
  166.       count--;
  167.     }
  168.     *dest = '\0';
  169.   }
  170. }
  171.  
  172. extern void Nlm_StrngCpy (Nlm_CharPtr dest, Nlm_CharPtr source, Nlm_sizeT maxsize)
  173.  
  174. {
  175.   Nlm_Uint4  count;
  176.  
  177.   if (dest != NULL && maxsize > 0) {
  178.     count = Nlm_StrngLen (source);
  179.     if (count >= maxsize) {
  180.       count = maxsize - 1;
  181.     }
  182.     while (count > 0) {
  183.       *dest = *source;
  184.       dest++;
  185.       source++;
  186.       count--;
  187.     }
  188.     *dest = '\0';
  189.   }
  190. }
  191.  
  192. static Nlm_Boolean Nlm_InNumber (Nlm_Char ch)
  193.  
  194. {
  195.   return (Nlm_Boolean) (ch >= '0' && ch <= '9') ;
  196. }
  197.  
  198. static Nlm_Char Nlm_Cap (Nlm_Char ch, Nlm_Boolean caseCounts)
  199.  
  200. {
  201.   if (caseCounts) {
  202.     return ch;
  203.   } else if (ch >= 'a' && ch <= 'z') {
  204.     return (Nlm_Char) (ch - ' ');
  205.   } else {
  206.     return ch;
  207.   }
  208. }
  209.  
  210. extern Nlm_Boolean Nlm_StrngPos (Nlm_CharPtr str, Nlm_CharPtr sub,
  211.                                  Nlm_Uint4 start, Nlm_Boolean caseCounts,
  212.                                  Nlm_Uint4Ptr match)
  213.  
  214. {
  215.   Nlm_Char     ch1;
  216.   Nlm_Char     ch2;
  217.   Nlm_Uint4    count;
  218.   Nlm_Boolean  found;
  219.   Nlm_Uint4    i;
  220.   Nlm_Uint4    j;
  221.   Nlm_Uint4    len;
  222.   Nlm_Uint4    max;
  223.   Nlm_Uint4    sublen;
  224.  
  225.   found = FALSE;
  226.   if (str != NULL && sub != NULL) {
  227.     len = Nlm_StrngLen (str);
  228.     sublen = Nlm_StrngLen (sub);
  229.     if (len < sublen) {
  230.       sublen = len;
  231.     }
  232.     max = len - sublen;
  233.     i = start;
  234.     if (match != NULL) {
  235.       *match = 0;
  236.     }
  237.     if (start < len) {
  238.       do {
  239.         found = TRUE;
  240.         j = 0;
  241.         count = sublen;
  242.         while (found && count > 0) {
  243.           ch1 = Nlm_Cap (str [i + j], caseCounts);
  244.           ch2 = Nlm_Cap (sub [j], caseCounts);
  245.           if (ch1 != ch2) {
  246.             found = FALSE;
  247.           }
  248.           j++;
  249.           count--;
  250.         }
  251.         if (found && match != NULL) {
  252.           *match = i;
  253.         }
  254.         i++;
  255.       } while ((! found) && (i <= max));
  256.     }
  257.     else {
  258.       found = FALSE;
  259.     }
  260.   }
  261.   return found;
  262. }
  263.  
  264. extern void Nlm_StrngSeg (Nlm_CharPtr dest, Nlm_CharPtr source,
  265.                           Nlm_Uint4 start, Nlm_Uint4 length,
  266.                           Nlm_sizeT maxsize)
  267.  
  268. {
  269.   Nlm_Uint4  count;
  270.   Nlm_Uint4  len;
  271.  
  272.   if (dest != NULL && source != NULL && maxsize > 0) {
  273.     count = length;
  274.     len = Nlm_StrngLen (source);
  275.     if (start + length > len) {
  276.       count = len - start;
  277.     }
  278.     if (count >= maxsize) {
  279.       count = maxsize - 1;
  280.     }
  281.     source += start;
  282.     while (count > 0) {
  283.       *dest = *source;
  284.       dest++;
  285.       source++;
  286.       count--;
  287.     }
  288.     *dest = '\0';
  289.   }
  290. }
  291.  
  292. extern void Nlm_StrngRep (Nlm_CharPtr dest, Nlm_CharPtr source,
  293.                           Nlm_Uint4 start, Nlm_sizeT maxsize)
  294.  
  295. {
  296.   Nlm_Uint4  count;
  297.  
  298.   if (dest != NULL && source != NULL && maxsize > 0) {
  299.     count = Nlm_StrngLen (source);
  300.     if (count + start >= maxsize) {
  301.       count = maxsize - start - 1;
  302.     }
  303.     dest += start;
  304.     while (count > 0) {
  305.       *dest = *source;
  306.       dest++;
  307.       source++;
  308.       count--;
  309.     }
  310.   }
  311. }
  312.  
  313. extern Nlm_Boolean Nlm_StrngEql (Nlm_CharPtr str1, Nlm_CharPtr str2,
  314.                                  Nlm_Boolean caseCounts)
  315.  
  316. {
  317.   return (Nlm_Boolean) (Nlm_StrngCmp (str1, str2, caseCounts) == 0);
  318. }
  319.  
  320. extern Nlm_Int2 Nlm_StrngCmp (Nlm_CharPtr str1, Nlm_CharPtr str2,
  321.                               Nlm_Boolean caseCounts)
  322.  
  323. {
  324.   Nlm_Uint4  count;
  325.   Nlm_Uint4  i;
  326.   Nlm_Uint4  len1;
  327.   Nlm_Uint4  len2;
  328.   Nlm_Int2   rsult;
  329.  
  330.   rsult = 0;
  331.   if (str1 != NULL && str2 != NULL) {
  332.     len1 = Nlm_StrngLen (str1);
  333.     len2 = Nlm_StrngLen (str2);
  334.     if (len1 > len2) {
  335.       count = len2;
  336.     } else {
  337.       count = len1;
  338.     }
  339.     i = 0;
  340.     while (count > 0 && Nlm_Cap (str1 [i], caseCounts) == Nlm_Cap (str2 [i], caseCounts)) {
  341.       i++;
  342.       count--;
  343.     }
  344.     if (count > 0) {
  345.       if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [i], caseCounts)) {
  346.         rsult = 1;
  347.       } else {
  348.         rsult = -1;
  349.       }
  350.     } else {
  351.       if (len1 > len2) {
  352.         rsult = 1;
  353.       } else if (len1 < len2) {
  354.         rsult = -1;
  355.       } else {
  356.         rsult = 0;
  357.       }
  358.     }
  359.   }
  360.   return rsult;
  361. }
  362.  
  363. extern Nlm_Int2 Nlm_SymblCmp (Nlm_CharPtr str1, Nlm_CharPtr str2,
  364.                               Nlm_Boolean caseCounts)
  365.  
  366. {
  367.   Nlm_Boolean  cont;
  368.   Nlm_Boolean  done;
  369.   Nlm_Uint4    i;
  370.   Nlm_Uint4    j;
  371.   Nlm_Uint4    len1;
  372.   Nlm_Uint4    len2;
  373.   Nlm_Uint4    num1;
  374.   Nlm_Uint4    num2;
  375.   Nlm_Int2     rsult;
  376.  
  377.   rsult = 0;
  378.   if (str1 != NULL && str2 != NULL) {
  379.     done = FALSE;
  380.     len1 = Nlm_StrngLen (str1);
  381.     len2 = Nlm_StrngLen (str2);
  382.     i = 0;
  383.     j = 0;
  384.     cont = (Nlm_Boolean) (len1 > 0 && len2 > 0);
  385.     while (cont) {
  386.       if (Nlm_InNumber (str1 [i]) && Nlm_InNumber (str2 [j])) {
  387.         num1 = 0;
  388.         while (i < len1 && Nlm_InNumber (str1 [i]) && (num1 < 429496729)) {
  389.           num1 *= 10;
  390.           num1 += (str1 [i] - '0');
  391.           i++;
  392.         }
  393.         num2 = 0;
  394.         while (j < len2 && Nlm_InNumber (str2 [j]) && (num2 < 429496729)) {
  395.           num2 *= 10;
  396.           num2 += (str2 [j] - '0');
  397.           j++;
  398.         }
  399.         if (num1 > num2) {
  400.           rsult = 1;
  401.           done = TRUE;
  402.           cont = FALSE;
  403.         } else if (num1 < num2) {
  404.           rsult = -1;
  405.           done = TRUE;
  406.           cont = FALSE;
  407.         } else {
  408.           cont = (Nlm_Boolean) (i < len1 && j < len2);
  409.         }
  410.       } else if (Nlm_Cap (str1 [i], caseCounts) > Nlm_Cap (str2 [j], caseCounts)) {
  411.         rsult = 1;
  412.         done = TRUE;
  413.         cont = FALSE;
  414.       } else if (Nlm_Cap (str1 [i], caseCounts) < Nlm_Cap (str2 [j], caseCounts)) {
  415.         rsult = -1;
  416.         done = TRUE;
  417.         cont = FALSE;
  418.       } else {
  419.         i++;
  420.         j++;
  421.         cont = (Nlm_Boolean) (i < len1 && j < len2);
  422.       }
  423.     }
  424.     if (done) {
  425.     } else if (i < len1 && j == len2) {
  426.       rsult = 1;
  427.     } else if (i == len1 && j < len2) {
  428.       rsult = -1;
  429.     } else {
  430.       rsult = 0;
  431.     }
  432.   }
  433.   return rsult;
  434. }
  435.  
  436. extern Nlm_Handle Nlm_SetString (Nlm_Handle h, Nlm_CharPtr str)
  437.  
  438. {
  439.   Nlm_sizeT       len;
  440.   Nlm_CharPtr  pp;
  441.  
  442.   if (str != NULL) {
  443.     len = Nlm_StringLen (str);
  444.     if (len > 0) {
  445.       if (h != NULL) {
  446.         h = Nlm_HandMore (h, len + 1);
  447.       } else {
  448.         h = Nlm_HandNew (len + 1);
  449.       }
  450.     } else if (h != NULL) {
  451.       Nlm_HandFree (h);
  452.       h = NULL;
  453.     }
  454.   } else {
  455.     Nlm_HandFree (h);
  456.     h = NULL;
  457.   }
  458.   if (h != NULL) {
  459.     pp = (Nlm_CharPtr) Nlm_HandLock (h);
  460.     if (pp != NULL) {
  461.       Nlm_StringNCpy (pp, str, len + 1);
  462.     }
  463.     Nlm_HandUnlock (h);
  464.   }
  465.   return h;
  466. }
  467.  
  468. extern void Nlm_GetString (Nlm_Handle h, Nlm_CharPtr str, Nlm_sizeT maxsize)
  469.  
  470. {
  471.   Nlm_CharPtr  pp;
  472.  
  473.   if (str != NULL) {
  474.     if (h != NULL) {
  475.       pp = (Nlm_CharPtr) Nlm_HandLock (h);
  476.       if (pp != NULL) {
  477.         Nlm_StringNCpy (str, pp, maxsize);
  478.       }
  479.       Nlm_HandUnlock (h);
  480.     } else {
  481.       Nlm_StringNCpy (str, "", maxsize);
  482.     }
  483.   }
  484. }
  485.  
  486. static void Nlm_MssgErrorProc (Nlm_ButtoN b)
  487.  
  488. {
  489.   errorBoxUp = FALSE;
  490.   errorBoxRsult = ANS_NO;
  491. }
  492.  
  493. static void Nlm_MssgFatalProc (Nlm_ButtoN b)
  494.  
  495. {
  496.   errorBoxUp = FALSE;
  497.   errorBoxRsult = ANS_NO;
  498. }
  499.  
  500. static void Nlm_MssgNoProc (Nlm_ButtoN b)
  501.  
  502. {
  503.   errorBoxUp = FALSE;
  504.   errorBoxRsult = ANS_NO;
  505. }
  506.  
  507. static void Nlm_MssgYesProc (Nlm_ButtoN b)
  508.  
  509. {
  510.   errorBoxUp = FALSE;
  511.   errorBoxRsult = ANS_YES;
  512. }
  513.  
  514. static void Nlm_MssgOkayProc (Nlm_ButtoN b)
  515.  
  516. {
  517.   errorBoxUp = FALSE;
  518.   errorBoxRsult = ANS_OK;
  519. }
  520.  
  521. static void Nlm_MssgRetryProc (Nlm_ButtoN b)
  522.  
  523. {
  524.   errorBoxUp = FALSE;
  525.   errorBoxRsult = ANS_RETRY;
  526. }
  527.  
  528. static void Nlm_MssgAbortProc (Nlm_ButtoN b)
  529.  
  530. {
  531.   errorBoxUp = FALSE;
  532.   errorBoxRsult = ANS_ABORT;
  533. }
  534.  
  535. static void Nlm_MssgCancelProc (Nlm_ButtoN b)
  536.  
  537. {
  538.   errorBoxUp = FALSE;
  539.   errorBoxRsult = ANS_CANCEL;
  540. }
  541.  
  542. static void Nlm_MssgIgnoreProc (Nlm_ButtoN b)
  543.  
  544. {
  545.   errorBoxUp = FALSE;
  546.   errorBoxRsult = ANS_IGNORE;
  547. }
  548.  
  549. static void Nlm_ClosePostProc (Nlm_WindoW w)
  550.  
  551. {
  552.   Nlm_Hide (w);
  553. }
  554.  
  555. static MsgAnswer LIBCALLBACK Nlm_VibMessageHook (MsgKey key, ErrSev severity,
  556.                                                  const char * caption, const char * message)
  557.  
  558. {
  559.   Nlm_CharPtr  buf;
  560.   Nlm_Int2     answer;
  561.   Nlm_sizeT       len;
  562.   Nlm_Int2     rsult;
  563.   Nlm_WindoW   tempPort;
  564.   Nlm_Int2     wtype;
  565. #ifdef WIN_MAC
  566.   Nlm_ButtoN   b [3];
  567.   Nlm_Char     ch;
  568.   void         *data;
  569.   Nlm_Int2     delta;
  570.   Nlm_Boolean  fatal;
  571.   Nlm_GrouP    g;
  572.   Nlm_Int2     i;
  573.   Nlm_Int2     j;
  574.   Nlm_Int2     margin;
  575.   Nlm_Int2     maxWidth;
  576.   Nlm_PoinT    npt;
  577.   Nlm_Int2     percent;
  578.   Nlm_RecT     r;
  579.   Nlm_Int2     rgt;
  580.   Nlm_WindoW   w;
  581.   Nlm_Int2     width;
  582. #endif
  583. #ifdef WIN_MOTIF
  584.   Nlm_ButtoN   b [3];
  585.   Nlm_Char     ch;
  586.   void         *data;
  587.   Nlm_Int2     delta;
  588.   Nlm_Boolean  fatal;
  589.   Nlm_GrouP    g;
  590.   Nlm_Int2     i;
  591.   Nlm_Int2     j;
  592.   Nlm_Int2     margin;
  593.   Nlm_Int2     maxWidth;
  594.   Nlm_PoinT    npt;
  595.   Nlm_Int2     percent;
  596.   Nlm_RecT     r;
  597.   Nlm_Int2     rgt;
  598.   Nlm_WindoW   w;
  599.   Nlm_Int2     width;
  600. #endif
  601.  
  602.   rsult = 0;
  603.   len = MIN (Nlm_StringLen (message), (Nlm_sizeT) 4094);
  604.   buf = (Nlm_CharPtr) Nlm_MemNew (len + 2);
  605.   Nlm_StringNCpy (buf, message, len);
  606.   if (key == KEY_NONE && severity == SEV_INFO) {
  607.     tempPort = Nlm_CurrentWindow ();
  608.     if (postWindow == NULL) {
  609.       postWindow = Nlm_DocumentWindow (-50, -90, -20, -20, "Message",
  610.                                        Nlm_ClosePostProc, NULL);
  611.       postPrompt = Nlm_StaticPrompt (postWindow, "", 30 * Nlm_stdCharWidth,
  612.                                      Nlm_stdLineHeight, Nlm_systemFont, 'c');
  613.     }
  614.     if (postWindow != NULL && postPrompt != NULL) {
  615.       Nlm_SetTitle (postPrompt, buf);
  616.       if (! Nlm_Visible (postWindow)) {
  617.         Nlm_Show (postWindow);
  618.       }
  619.       Nlm_Select (postWindow);
  620.     }
  621.     Nlm_RestorePort (tempPort);
  622.     return (MsgAnswer) 0;
  623.   }
  624. #ifndef WIN_MSWIN
  625.   data = Nlm_GetAppProperty ("VibrantMessageWidthMax");
  626.   if (data != NULL) {
  627.     percent = (Nlm_Int2) data;
  628.     if (percent < 0) {
  629.       percent = 100;
  630.     }
  631.   } else {
  632.     percent = 100;
  633.   }
  634.   percent = MAX (percent, 25);
  635.   percent = MIN (percent, 95);
  636.   maxWidth = (Nlm_Int2) ((Nlm_Int4) (Nlm_screenRect.right - Nlm_screenRect.left) *
  637.               (Nlm_Int4) percent / (Nlm_Int4) 100) - 40;
  638.   maxWidth = MAX (maxWidth, 100);
  639. #endif
  640. #ifdef WIN_MAC
  641.   w = Nlm_ModalWindow (-50, -20, -20, -20, NULL);
  642.   g = Nlm_HiddenGroup (w, 0, 10, NULL);
  643.   Nlm_GetNextPosition (g, &npt);
  644.   npt.x += 6;
  645.   Nlm_SetNextPosition (g, npt);
  646.   i = 0;
  647.   while (Nlm_StringLen (buf + i) > 0) {
  648.     width = 0;
  649.     j = 0;
  650.     while (buf [i + j] == ' ') {
  651.       i++;
  652.     }
  653.     ch = buf [i + j];
  654.     width += Nlm_CharWidth (ch);
  655.     while (ch != '\0' && ch != '\n' && ch != '\r' && width <= maxWidth) {
  656.       j++;
  657.       ch = buf [i + j];
  658.       width += Nlm_CharWidth (ch);
  659.     }
  660.     if (width > maxWidth) {
  661.       ch = buf [i + j];
  662.       while (j > 0 && ch != ' ' && ch != '-') {
  663.         j--;
  664.         ch = buf [i + j];
  665.       }
  666.     }
  667.     if (ch == '\n' || ch == '\r') {
  668.       buf [i + j] = '\0';
  669.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  670.       i += j + 1;
  671.     } else {
  672.       buf [i + j] = '\0';
  673.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  674.       buf [i + j] = ch;
  675.       i += j;
  676.     }
  677.   }
  678.   Nlm_GetPosition (g, &r);
  679.   margin = r.right;
  680.   Nlm_Break ((Nlm_GraphiC) w);
  681.   b [0] = NULL;
  682.   b [1] = NULL;
  683.   b [2] = NULL;
  684.   switch (key) {
  685.     case KEY_OK:
  686.       if (severity == SEV_ERROR) {
  687.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgErrorProc);
  688.       } else if (severity == SEV_FATAL) {
  689.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgFatalProc);
  690.       } else {
  691.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  692.       }
  693.       break;
  694.     case KEY_RC:
  695.       b [0] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  696.       Nlm_Advance ((Nlm_GraphiC) w);
  697.       b [1] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  698.       break;
  699.     case KEY_ARI:
  700.       b [0] = Nlm_PushButton (w, "Abort", Nlm_MssgAbortProc);
  701.       Nlm_Advance ((Nlm_GraphiC) w);
  702.       b [1] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  703.       Nlm_Advance ((Nlm_GraphiC) w);
  704.       b [2] = Nlm_PushButton (w, "Ignore", Nlm_MssgIgnoreProc);
  705.       break;
  706.     case KEY_YN:
  707.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  708.       Nlm_Advance ((Nlm_GraphiC) w);
  709.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  710.       break;
  711.     case KEY_YNC:
  712.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  713.       Nlm_Advance ((Nlm_GraphiC) w);
  714.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  715.       Nlm_Advance ((Nlm_GraphiC) w);
  716.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  717.       break;
  718.     case KEY_OKC:
  719.       b [1] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  720.       Nlm_Advance ((Nlm_GraphiC) w);
  721.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  722.       break;
  723.     case KEY_NONE:
  724.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  725.       break;
  726.     default:
  727.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  728.       break;
  729.   }
  730.   i = 2;
  731.   while (i >= 0 && b [i] == NULL) {
  732.     i--;
  733.   }
  734.   if (i >= 0) {
  735.     Nlm_GetPosition (b [i], &r);
  736.     delta = (margin - r.right) / 2;
  737.     if (delta > 0) {
  738.       while (i >= 0) {
  739.         Nlm_GetPosition (b [i], &r);
  740.         Nlm_OffsetRect (&r, delta, 0);
  741.         Nlm_SetPosition (b [i], &r);
  742.         i--;
  743.       }
  744.     } else if (delta < 0) {
  745.       Nlm_GetPosition (g, &r);
  746.       Nlm_OffsetRect (&r, -delta, 0);
  747.       Nlm_SetPosition (g, &r);
  748.     }
  749.   }
  750.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  751.   Nlm_ArrowCursor ();
  752.   errorBoxUp = TRUE;
  753.   errorBoxRsult = 0;
  754.   while (errorBoxUp) {
  755.     Nlm_ProcessExternalEvent ();
  756.   }
  757.   Nlm_ProcessAnEvent ();
  758.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  759.   rsult = errorBoxRsult;
  760. #endif
  761. #ifdef WIN_MSWIN
  762.   wtype = MB_OK;
  763.   switch (key) {
  764.     case KEY_OK:
  765.       if (severity == SEV_ERROR) {
  766.         wtype = MB_OK;
  767.       } else if (severity == SEV_FATAL) {
  768.         wtype = MB_OK;
  769.       } else {
  770.         wtype = MB_OK;
  771.       }
  772.       break;
  773.     case KEY_RC:
  774.       wtype = MB_RETRYCANCEL;
  775.       break;
  776.     case KEY_ARI:
  777.       wtype = MB_ABORTRETRYIGNORE;
  778.       break;
  779.     case KEY_YN:
  780.       wtype = MB_YESNO;
  781.       break;
  782.     case KEY_YNC:
  783.       wtype = MB_YESNOCANCEL;
  784.       break;
  785.     case KEY_OKC:
  786.       wtype = MB_OKCANCEL;
  787.       break;
  788.     case KEY_NONE:
  789.       wtype = MB_OK;
  790.       break;
  791.     default:
  792.       break;
  793.   }
  794.   answer = MessageBox (Nlm_currentHWnd, buf, "", wtype);
  795.   switch (answer) {
  796.     case IDNO:
  797.       rsult = ANS_NO;
  798.       break;
  799.     case IDYES:
  800.       rsult = ANS_YES;
  801.       break;
  802.     case IDOK:
  803.       rsult = ANS_OK;
  804.       break;
  805.     case IDRETRY:
  806.       rsult = ANS_RETRY;
  807.       break;
  808.     case IDABORT:
  809.       rsult = ANS_ABORT;
  810.       break;
  811.     case IDCANCEL:
  812.       rsult = ANS_CANCEL;
  813.       break;
  814.     case IDIGNORE:
  815.       rsult = ANS_IGNORE;
  816.       break;
  817.     default:
  818.       break;
  819.   }
  820. #endif
  821. #ifdef WIN_MOTIF
  822.   w = Nlm_ModalWindow (-50, -20, -20, -20, NULL);
  823.   g = Nlm_HiddenGroup (w, 0, 10, NULL);
  824.   Nlm_GetNextPosition (g, &npt);
  825.   npt.x += 6;
  826.   Nlm_SetNextPosition (g, npt);
  827.   i = 0;
  828.   while (Nlm_StringLen (buf + i) > 0) {
  829.     width = 0;
  830.     j = 0;
  831.     while (buf [i + j] == ' ') {
  832.       i++;
  833.     }
  834.     ch = buf [i + j];
  835.     width += Nlm_CharWidth (ch);
  836.     while (ch != '\0' && ch != '\n' && ch != '\r' && width <= maxWidth) {
  837.       j++;
  838.       ch = buf [i + j];
  839.       width += Nlm_CharWidth (ch);
  840.     }
  841.     if (width > maxWidth) {
  842.       ch = buf [i + j];
  843.       while (j > 0 && ch != ' ' && ch != '-') {
  844.         j--;
  845.         ch = buf [i + j];
  846.       }
  847.     }
  848.     if (ch == '\n' || ch == '\r') {
  849.       buf [i + j] = '\0';
  850.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  851.       i += j + 1;
  852.     } else {
  853.       buf [i + j] = '\0';
  854.       Nlm_StaticPrompt (g, buf + i, 0, 0, Nlm_systemFont, 'l');
  855.       buf [i + j] = ch;
  856.       i += j;
  857.     }
  858.   }
  859.   Nlm_GetPosition (g, &r);
  860.   margin = r.right;
  861.   Nlm_Break ((Nlm_GraphiC) w);
  862.   b [0] = NULL;
  863.   b [1] = NULL;
  864.   b [2] = NULL;
  865.   switch (key) {
  866.     case KEY_OK:
  867.       if (severity == SEV_ERROR) {
  868.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgErrorProc);
  869.       } else if (severity == SEV_FATAL) {
  870.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgFatalProc);
  871.       } else {
  872.         b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  873.       }
  874.       break;
  875.     case KEY_RC:
  876.       b [0] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  877.       Nlm_Advance ((Nlm_GraphiC) w);
  878.       b [1] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  879.       break;
  880.     case KEY_ARI:
  881.       b [0] = Nlm_PushButton (w, "Abort", Nlm_MssgAbortProc);
  882.       Nlm_Advance ((Nlm_GraphiC) w);
  883.       b [1] = Nlm_PushButton (w, "Retry", Nlm_MssgRetryProc);
  884.       Nlm_Advance ((Nlm_GraphiC) w);
  885.       b [2] = Nlm_PushButton (w, "Ignore", Nlm_MssgIgnoreProc);
  886.       break;
  887.     case KEY_YN:
  888.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  889.       Nlm_Advance ((Nlm_GraphiC) w);
  890.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  891.       break;
  892.     case KEY_YNC:
  893.       b [0] = Nlm_PushButton (w, "Yes", Nlm_MssgYesProc);
  894.       Nlm_Advance ((Nlm_GraphiC) w);
  895.       b [1] = Nlm_PushButton (w, "No", Nlm_MssgNoProc);
  896.       Nlm_Advance ((Nlm_GraphiC) w);
  897.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  898.       break;
  899.     case KEY_OKC:
  900.       b [1] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  901.       Nlm_Advance ((Nlm_GraphiC) w);
  902.       b [2] = Nlm_PushButton (w, "Cancel", Nlm_MssgCancelProc);
  903.       break;
  904.     case KEY_NONE:
  905.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  906.       break;
  907.     default:
  908.       b [0] = Nlm_PushButton (w, "OK", Nlm_MssgOkayProc);
  909.       break;
  910.   }
  911.   i = 2;
  912.   while (i >= 0 && b [i] == NULL) {
  913.     i--;
  914.   }
  915.   if (i >= 0) {
  916.     Nlm_GetPosition (b [i], &r);
  917.     delta = (margin - r.right) / 2;
  918.     if (delta > 0) {
  919.       while (i >= 0) {
  920.         Nlm_GetPosition (b [i], &r);
  921.         Nlm_OffsetRect (&r, delta, 0);
  922.         Nlm_SetPosition (b [i], &r);
  923.         i--;
  924.       }
  925.     } else if (delta < 0) {
  926.       Nlm_GetPosition (g, &r);
  927.       Nlm_OffsetRect (&r, -delta, 0);
  928.       Nlm_SetPosition (g, &r);
  929.     }
  930.   }
  931.   Nlm_DoShow ((Nlm_GraphiC) w, TRUE, TRUE);
  932.   errorBoxUp = TRUE;
  933.   errorBoxRsult = 0;
  934.   while (errorBoxUp) {
  935.     Nlm_ProcessAnEvent ();
  936.   }
  937.   Nlm_DoRemove ((Nlm_GraphiC) w, TRUE);
  938.   rsult = errorBoxRsult;
  939. #endif
  940.   Nlm_MemFree (buf);
  941.   return (MsgAnswer) rsult;
  942. }
  943.  
  944. typedef struct monitextra {
  945.   Nlm_WindoW   wind;
  946.   Nlm_PaneL    pnl;
  947. } Nlm_VibMonExtra, PNTR Nlm_VibMonPtr;
  948.  
  949. static void Nlm_SelectMonitor (Nlm_WindoW w)
  950.  
  951. {
  952.   Nlm_WindowTool  wptr;
  953. #ifdef WIN_MOTIF
  954.   Nlm_ShellTool   shl;
  955. #endif
  956.  
  957.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) w);
  958. #ifdef WIN_MAC
  959.   SelectWindow (wptr);
  960.   SetPort (wptr);
  961.   Nlm_SetUpdateRegion (wptr);
  962.   Nlm_ResetDrawingTools ();
  963. #endif
  964. #ifdef WIN_MSWIN
  965.   BringWindowToTop (wptr);
  966.   Nlm_currentHDC = Nlm_ParentWindowPort ((Nlm_GraphiC) w);
  967.   Nlm_currentHWnd = wptr;
  968. #endif
  969. #ifdef WIN_MOTIF
  970.   if (Nlm_currentXDisplay != NULL) {
  971.     shl = Nlm_ParentWindowShell ((Nlm_GraphiC) w);
  972.     XMapRaised (Nlm_currentXDisplay, XtWindow (shl));
  973.   }
  974. #endif
  975.   Nlm_currentWindowTool = wptr;
  976. }
  977.  
  978. static int Nlm_VibMonStrValue (Nlm_MonitorPtr mon)
  979.  
  980. {
  981.   Nlm_VibMonPtr  vmp;
  982.   Nlm_PaneL      pnl;
  983.   Nlm_RecT       r;
  984.   Nlm_WindoW     tempPort;
  985.   Nlm_WindoW     wind;
  986. #ifdef WIN_MOTIF
  987.   Nlm_Uint4      tempBackColor;
  988.   Nlm_Uint4      tempForeColor;
  989.   Nlm_Int2       tempXOffset;
  990.   Nlm_Int2       tempYOffset;
  991.   Window         tempXWind;
  992. #endif
  993.  
  994.   if (mon == NULL || mon->type != MonType_Str || mon->extra == NULL) {
  995.     return 0;
  996.   }
  997.   vmp = (Nlm_VibMonPtr) mon->extra;
  998.   pnl = vmp->pnl;
  999.   wind = vmp->wind;
  1000.   tempPort = Nlm_CurrentWindow ();
  1001. #ifdef WIN_MOTIF
  1002.   tempXWind = Nlm_currentXWindow;
  1003.   tempBackColor = Nlm_XbackColor;
  1004.   tempForeColor = Nlm_XforeColor;
  1005.   tempXOffset = Nlm_XOffset;
  1006.   tempYOffset = Nlm_YOffset;
  1007. #endif
  1008.   Nlm_UseWindow (wind);
  1009.   Nlm_SelectMonitor (wind);
  1010.   Nlm_Select (pnl);
  1011.   Nlm_GetRect ((Nlm_GraphiC) pnl, &r);
  1012.   Nlm_InsetRect (&r, 2, 2);
  1013.   Nlm_DrawString (&r, (Nlm_CharPtr) mon->strValue, 'l', FALSE);
  1014.   Nlm_UseWindow (tempPort);
  1015. #ifdef WIN_MOTIF
  1016.   Nlm_currentXWindow = tempXWind;
  1017.   Nlm_XbackColor = tempBackColor;
  1018.   Nlm_XforeColor = tempForeColor;
  1019.   Nlm_XOffset = tempXOffset;
  1020.   Nlm_YOffset = tempYOffset;
  1021.   if (Nlm_currentXDisplay != NULL) {
  1022.     XSync (Nlm_currentXDisplay, FALSE);
  1023.   }
  1024. #endif
  1025.   return 0;
  1026. }
  1027.  
  1028. static int Nlm_VibMonIntValue (Nlm_MonitorPtr mon)
  1029.  
  1030. {
  1031.   Nlm_Int4       from;
  1032.   Nlm_VibMonPtr  vmp;
  1033.   Nlm_PaneL      pnl;
  1034.   Nlm_RecT       r;
  1035.   Nlm_Int4       range;
  1036.   Nlm_Int2       right;
  1037.   Nlm_WindoW     tempPort;
  1038.   Nlm_Int4       to;
  1039.   Nlm_Int4       value;
  1040.   Nlm_Int4       width;
  1041.   Nlm_WindoW     wind;
  1042. #ifdef WIN_MOTIF
  1043.   Nlm_Uint4      tempBackColor;
  1044.   Nlm_Uint4      tempForeColor;
  1045.   Nlm_Int2       tempXOffset;
  1046.   Nlm_Int2       tempYOffset;
  1047.   Window         tempXWind;
  1048. #endif
  1049.  
  1050.   if (mon == NULL || mon->type != MonType_Int || mon->extra == NULL) {
  1051.     return 0;
  1052.   }
  1053.   vmp = (Nlm_VibMonPtr) mon->extra;
  1054.   from = MIN (mon->num1, mon->num2);
  1055.   to = MAX (mon->num1, mon->num2);
  1056.   range = to - from;
  1057.   value = mon->intValue;
  1058.   value = MAX (value, from);
  1059.   value = MIN (value, to);
  1060.   value -= from;
  1061.   pnl = vmp->pnl;
  1062.   wind = vmp->wind;
  1063.   tempPort = Nlm_CurrentWindow ();
  1064. #ifdef WIN_MOTIF
  1065.   tempXWind = Nlm_currentXWindow;
  1066.   tempBackColor = Nlm_XbackColor;
  1067.   tempForeColor = Nlm_XforeColor;
  1068.   tempXOffset = Nlm_XOffset;
  1069.   tempYOffset = Nlm_YOffset;
  1070. #endif
  1071.   Nlm_UseWindow (wind);
  1072.   Nlm_SelectMonitor (wind);
  1073.   Nlm_Select (pnl);
  1074.   Nlm_GetRect ((Nlm_GraphiC) pnl, &r);
  1075.   Nlm_FrameRect (&r);
  1076.   Nlm_InsetRect (&r, 2, 2);
  1077.   value = MAX (value, 0);
  1078.   value = MIN (value, range);
  1079.   width = (Nlm_Int4) (r.right - r.left);
  1080.   right = r.right;
  1081.   r.right = r.left + (Nlm_Int2) (width * value / range);
  1082. #ifdef DCLAP
  1083. #ifdef WIN_MOTIF
  1084.     /* my motif aint' showing any progress bar... */
  1085.   Nlm_Black();
  1086. #endif
  1087. #endif
  1088.  
  1089.   Nlm_PaintRect (&r);
  1090.   r.left = r.right;
  1091.   r.right = right;
  1092.   Nlm_EraseRect (&r);
  1093.   Nlm_UseWindow (tempPort);
  1094. #ifdef WIN_MOTIF
  1095.   Nlm_currentXWindow = tempXWind;
  1096.   Nlm_XbackColor = tempBackColor;
  1097.   Nlm_XforeColor = tempForeColor;
  1098.   Nlm_XOffset = tempXOffset;
  1099.   Nlm_YOffset = tempYOffset;
  1100.   if (Nlm_currentXDisplay != NULL) {
  1101.     XSync (Nlm_currentXDisplay, FALSE);
  1102.   }
  1103. #endif
  1104.   return 0;
  1105. }
  1106.  
  1107. static int Nlm_VibMonCreate (Nlm_MonitorPtr mon)
  1108.  
  1109. {
  1110.   Nlm_VibMonPtr  vmp;
  1111.   Nlm_PaneL      pnl;
  1112.   Nlm_WindoW     wind;
  1113.  
  1114.   if (mon != NULL) {
  1115.     vmp = (Nlm_VibMonPtr) Nlm_MemNew (sizeof (Nlm_VibMonExtra));
  1116.     mon->extra = (Nlm_VoidPtr) vmp;
  1117.     if (vmp != NULL) {
  1118.       wind = Nlm_FixedWindow (-50, -90, -10, -10, (Nlm_CharPtr) mon->strTitle, NULL);
  1119.       if (mon->type == MonType_Int) {
  1120.         pnl = Nlm_SimplePanel (wind, 200, 20, NULL);
  1121.       } else if (mon->type == MonType_Str) {
  1122.         pnl = Nlm_SimplePanel (wind, Nlm_stdCharWidth * (Nlm_Int2) mon->num1 + 6,
  1123.                                Nlm_stdLineHeight + 4, NULL);
  1124.       } else {
  1125.         pnl = Nlm_SimplePanel (wind, 200, 20, NULL);
  1126.       }
  1127.       vmp->wind = wind;
  1128.       vmp->pnl = pnl;
  1129.       Nlm_Show (wind);
  1130.     }
  1131.   }
  1132.   return TRUE;
  1133. }
  1134.  
  1135. static int Nlm_VibMonDestroy (Nlm_MonitorPtr mon)
  1136.  
  1137. {
  1138.   Nlm_VibMonPtr  vmp;
  1139.  
  1140.   if (mon != NULL) {
  1141.     vmp = (Nlm_VibMonPtr) mon->extra;
  1142.     if (vmp != NULL) {
  1143.       Nlm_Remove (vmp->wind);
  1144.       Nlm_MemFree (vmp);
  1145.     }
  1146.   }
  1147.   return 0;
  1148. }
  1149.  
  1150. static int LIBCALLBACK Nlm_VibMonitorHook (Nlm_MonitorPtr mon, MonCode code)
  1151.  
  1152. {
  1153.   switch (code) {
  1154.     case MonCode_Create :
  1155.       return Nlm_VibMonCreate (mon);
  1156.       break;
  1157.     case MonCode_Destroy :
  1158.       return Nlm_VibMonDestroy (mon);
  1159.       break;
  1160.     case MonCode_IntValue :
  1161.       return Nlm_VibMonIntValue (mon);
  1162.       break;
  1163.     case MonCode_StrValue :
  1164.       return Nlm_VibMonStrValue (mon);
  1165.       break;
  1166.     default :
  1167.       break;
  1168.   }
  1169.   return 0;
  1170. }
  1171.  
  1172. static void LIBCALLBACK Nlm_VibBeepHook (void)
  1173.  
  1174. {
  1175. #ifdef OS_MAC
  1176.   SysBeep (60);
  1177. #endif
  1178. #ifdef WIN_MSWIN
  1179.   MessageBeep (0);
  1180. #endif
  1181. #ifdef WIN_MOTIF
  1182.   if (Nlm_currentXDisplay != NULL) {
  1183.     XBell (Nlm_currentXDisplay, 0);
  1184.   }
  1185. #endif
  1186. }
  1187.  
  1188. extern void Nlm_InitVibrantHooks (void)
  1189.  
  1190. {
  1191.   Nlm_SetBeepHook (Nlm_VibBeepHook);
  1192.   Nlm_SetMonitorHook (Nlm_VibMonitorHook);
  1193.   Nlm_SetMessageHook (Nlm_VibMessageHook);
  1194. }
  1195.  
  1196. extern void Nlm_MousePosition (Nlm_PointPtr pt)
  1197.  
  1198. {
  1199. #ifdef WIN_MAC
  1200.   Nlm_PointTool  ptool;
  1201.  
  1202.   GetMouse (&ptool);
  1203.   if (pt != NULL) {
  1204.     Nlm_PointToolToPoinT (ptool, pt);
  1205.   }
  1206. #endif
  1207. #ifdef WIN_MSWIN
  1208.   Nlm_PointTool  ptool;
  1209.  
  1210.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  1211.     GetCursorPos (&ptool);
  1212.     ScreenToClient (Nlm_currentHWnd, &ptool);
  1213.     Nlm_PointToolToPoinT (ptool, pt);
  1214.   }
  1215. #endif
  1216. #ifdef WIN_MOTIF
  1217. #endif
  1218. }
  1219.  
  1220. extern Nlm_Boolean Nlm_MouseButton (void)
  1221.  
  1222. {
  1223. #ifdef WIN_MAC
  1224.   return (Button ());
  1225. #endif
  1226. #ifdef WIN_MSWIN
  1227.   return (Nlm_Boolean) ((GetAsyncKeyState (VK_LBUTTON) & 0x8000) != 0);
  1228. #endif
  1229. #ifdef WIN_MOTIF
  1230.   return FALSE;
  1231. #endif
  1232. }
  1233.  
  1234. extern Nlm_Int4 Nlm_ComputerTime (void)
  1235.  
  1236. {
  1237. #ifdef WIN_MAC
  1238.   return (TickCount ()); /* 60ths of second */
  1239. #endif
  1240. #ifdef WIN_MSWIN
  1241.   return (GetCurrentTime ()); /* milliseconds */
  1242. #endif
  1243. #ifdef WIN_MOTIF
  1244. #ifdef DCLAP
  1245.     return  time(NULL) * 60;  /* 60ths of seconds */
  1246. #endif
  1247. #endif
  1248. }
  1249.  
  1250. extern void Nlm_Version (Nlm_CharPtr vsn, Nlm_sizeT maxsize)
  1251.  
  1252. {
  1253.   Nlm_StringNCpy (vsn, "NCBI VIBRANT Version 0.8 (8 May 91)", maxsize);
  1254. }
  1255.  
  1256. extern void Nlm_Advance (Nlm_Handle a)
  1257.  
  1258. {
  1259.   Nlm_BoxData  bdata;
  1260.  
  1261.   if (a != NULL) {
  1262.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1263.     bdata.nextPoint.y = bdata.topRow;
  1264.     bdata.nextPoint.x = bdata.nextCol;
  1265.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1266.   }
  1267. }
  1268.  
  1269. extern void Nlm_Break (Nlm_Handle a)
  1270.  
  1271. {
  1272.   Nlm_BoxData  bdata;
  1273.  
  1274.   if (a != NULL) {
  1275.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1276.     bdata.topRow = bdata.limitPoint.y + bdata.ySpacing;
  1277.     bdata.nextCol = bdata.resetPoint.x;
  1278.     bdata.nextPoint.y = bdata.topRow;
  1279.     bdata.nextPoint.x = bdata.nextCol;
  1280.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1281.   }
  1282. }
  1283.  
  1284. extern void Nlm_RecordRect (Nlm_GraphiC a, Nlm_RectPtr r)
  1285.  
  1286. {
  1287.   Nlm_BoxData  bdata;
  1288.   Nlm_Int2     nc;
  1289.   Nlm_Int2     nr;
  1290.  
  1291.   if (a != NULL && r != NULL) {
  1292.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1293.     nr = r->bottom;
  1294.     if (nr > bdata.limitPoint.y) {
  1295.       bdata.limitPoint.y = nr;
  1296.     }
  1297.     nc = r->right;
  1298.     if (nc > bdata.limitPoint.x) {
  1299.       bdata.limitPoint.x = nc;
  1300.     }
  1301.     nc = r->right + bdata.xSpacing;
  1302.     if (nc > bdata.nextCol) {
  1303.       bdata.nextCol = nc;
  1304.     }
  1305.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1306.   }
  1307. }
  1308.  
  1309. extern void Nlm_NextPosition (Nlm_GraphiC a, Nlm_RectPtr r)
  1310.  
  1311. {
  1312.   Nlm_BoxData  bdata;
  1313.  
  1314.   if (a != NULL && r != NULL) {
  1315.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1316.     bdata.nextPoint.y = r->bottom + bdata.ySpacing;
  1317.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1318.   }
  1319. }
  1320.  
  1321. extern void Nlm_SetNextPosition (Nlm_Handle a, Nlm_PoinT nps)
  1322.  
  1323. {
  1324.   Nlm_BoxData  bdata;
  1325.  
  1326.   if (a != NULL) {
  1327.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1328.     bdata.nextPoint = nps;
  1329.     bdata.topRow = nps.y;
  1330.     Nlm_SetBoxData ((Nlm_BoX) a, &bdata);
  1331.   }
  1332. }
  1333.  
  1334. extern void Nlm_GetNextPosition (Nlm_Handle a, Nlm_PointPtr nps)
  1335.  
  1336. {
  1337.   Nlm_BoxData  bdata;
  1338.  
  1339.   if (a != NULL && nps != NULL) {
  1340.     Nlm_GetBoxData ((Nlm_BoX) a, &bdata);
  1341.     *nps = bdata.nextPoint;
  1342.   }
  1343. }
  1344.  
  1345. extern Nlm_GphPrcsPtr Nlm_GetClassPtr (Nlm_GraphiC a)
  1346.  
  1347. {
  1348.   Nlm_GphPrcsPtr   classPtr;
  1349.   Nlm_GraphicData  gdata;
  1350.  
  1351.   classPtr = NULL;
  1352.   if (a != NULL) {
  1353.     Nlm_GetGraphicData (a, &gdata);
  1354.     classPtr = gdata.classptr;
  1355.   }
  1356.   return classPtr;
  1357. }
  1358.  
  1359. #ifdef WIN_MAC
  1360. extern Nlm_Boolean Nlm_DoClick (Nlm_GraphiC a, Nlm_PoinT pt)
  1361.  
  1362. {
  1363.   Nlm_GphPrcsPtr  classPtr;
  1364.   Nlm_Boolean     cont;
  1365.   Nlm_Boolean     (*clk) PROTO((Nlm_GraphiC, Nlm_PoinT));
  1366.   Nlm_Boolean     rsult;
  1367.  
  1368.   rsult = FALSE;
  1369.   cont = TRUE;
  1370.   classPtr = Nlm_GetClassPtr (a);
  1371.   while (classPtr != NULL && cont) {
  1372.     clk = classPtr->click;
  1373.     if (clk != NULL) {
  1374.       rsult = clk (a, pt);
  1375.       cont = FALSE;
  1376.     } else {
  1377.       classPtr = classPtr->ancestor;
  1378.     }
  1379.   }
  1380.   return rsult;
  1381. }
  1382.  
  1383. extern Nlm_Boolean Nlm_DoKey (Nlm_GraphiC a, Nlm_Char ch)
  1384.  
  1385. {
  1386.   Nlm_GphPrcsPtr  classPtr;
  1387.   Nlm_Boolean     cont;
  1388.   Nlm_Boolean     (*ky) PROTO((Nlm_GraphiC, Nlm_Char));
  1389.   Nlm_Boolean     rsult;
  1390.  
  1391.   rsult = FALSE;
  1392.   cont = TRUE;
  1393.   classPtr = Nlm_GetClassPtr (a);
  1394.   while (classPtr != NULL && cont) {
  1395.     ky = classPtr->key;
  1396.     if (ky != NULL) {
  1397.       rsult = ky (a, ch);
  1398.       cont = FALSE;
  1399.     } else {
  1400.       classPtr = classPtr->ancestor;
  1401.     }
  1402.   }
  1403.   return rsult;
  1404. }
  1405.  
  1406. extern void Nlm_DoDraw (Nlm_GraphiC a)
  1407.  
  1408. {
  1409.   Nlm_GphPrcsPtr  classPtr;
  1410.   Nlm_Boolean     cont;
  1411.   void            (*drw) PROTO((Nlm_GraphiC));
  1412.  
  1413.   cont = TRUE;
  1414.   classPtr = Nlm_GetClassPtr (a);
  1415.   while (classPtr != NULL && cont) {
  1416.     drw = classPtr->draw;
  1417.     if (drw != NULL) {
  1418.       drw (a);
  1419.       cont = FALSE;
  1420.     } else {
  1421.       classPtr = classPtr->ancestor;
  1422.     }
  1423.   }
  1424. }
  1425.  
  1426. extern Nlm_Boolean Nlm_DoIdle (Nlm_GraphiC a, Nlm_PoinT pt)
  1427.  
  1428. {
  1429.   Nlm_GphPrcsPtr  classPtr;
  1430.   Nlm_Boolean     cont;
  1431.   Nlm_Boolean     (*idl) PROTO((Nlm_GraphiC, Nlm_PoinT));
  1432.   Nlm_Boolean     rsult;
  1433.  
  1434.   rsult = FALSE;
  1435.   cont = TRUE;
  1436.   classPtr = Nlm_GetClassPtr (a);
  1437.   while (classPtr != NULL && cont) {
  1438.     idl = classPtr->idle;
  1439.     if (idl != NULL) {
  1440.       rsult = idl (a, pt);
  1441.       cont = FALSE;
  1442.     } else {
  1443.       classPtr = classPtr->ancestor;
  1444.     }
  1445.   }
  1446.   return rsult;
  1447. }
  1448. #endif
  1449.  
  1450. #ifdef WIN_MSWIN
  1451. extern Nlm_Boolean Nlm_DoCommand (Nlm_GraphiC a)
  1452.  
  1453. {
  1454.   Nlm_GphPrcsPtr  classPtr;
  1455.   Nlm_Boolean     cont;
  1456.   Nlm_Boolean     (*cmd) PROTO((Nlm_GraphiC));
  1457.   Nlm_Boolean     rsult;
  1458.  
  1459.   rsult = FALSE;
  1460.   cont = TRUE;
  1461.   classPtr = Nlm_GetClassPtr (a);
  1462.   while (classPtr != NULL && cont) {
  1463.     cmd = classPtr->command;
  1464.     if (cmd != NULL) {
  1465.       rsult = cmd (a);
  1466.       cont = FALSE;
  1467.     } else {
  1468.       classPtr = classPtr->ancestor;
  1469.     }
  1470.   }
  1471.   return rsult;
  1472. }
  1473. #endif
  1474.  
  1475. #ifdef WIN_MOTIF
  1476. extern void Nlm_DoCallback (Nlm_GraphiC a)
  1477.  
  1478. {
  1479.   Nlm_GphPrcsPtr  classPtr;
  1480.   Nlm_Boolean     cont;
  1481.   void            (*clb) PROTO((Nlm_GraphiC));
  1482.  
  1483.   cont = TRUE;
  1484.   classPtr = Nlm_GetClassPtr (a);
  1485.   while (classPtr != NULL && cont) {
  1486.     clb = classPtr->callback;
  1487.     if (clb != NULL) {
  1488.       clb (a);
  1489.       cont = FALSE;
  1490.     } else {
  1491.       classPtr = classPtr->ancestor;
  1492.     }
  1493.   }
  1494. }
  1495. #endif
  1496.  
  1497. extern void Nlm_DoShow (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1498.  
  1499. {
  1500.   Nlm_GphPrcsPtr  classPtr;
  1501.   Nlm_Boolean     cont;
  1502.   void            (*shw) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1503.  
  1504.   cont = TRUE;
  1505.   classPtr = Nlm_GetClassPtr (a);
  1506.   while (classPtr != NULL && cont) {
  1507.     shw = classPtr->show;
  1508.     if (shw != NULL) {
  1509.       shw (a, setFlag, savePort);
  1510.       cont = FALSE;
  1511.     } else {
  1512.       classPtr = classPtr->ancestor;
  1513.     }
  1514.   }
  1515. }
  1516.  
  1517. extern void Nlm_DoHide (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1518.  
  1519. {
  1520.   Nlm_GphPrcsPtr  classPtr;
  1521.   Nlm_Boolean     cont;
  1522.   void            (*hid) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1523.  
  1524.   cont = TRUE;
  1525.   classPtr = Nlm_GetClassPtr (a);
  1526.   while (classPtr != NULL && cont) {
  1527.     hid = classPtr->hide;
  1528.     if (hid != NULL) {
  1529.       hid (a, setFlag, savePort);
  1530.       cont = FALSE;
  1531.     } else {
  1532.       classPtr = classPtr->ancestor;
  1533.     }
  1534.   }
  1535. }
  1536.  
  1537. extern void Nlm_DoEnable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1538.  
  1539. {
  1540.   Nlm_GphPrcsPtr  classPtr;
  1541.   Nlm_Boolean     cont;
  1542.   void            (*enbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1543.  
  1544.   cont = TRUE;
  1545.   classPtr = Nlm_GetClassPtr (a);
  1546.   while (classPtr != NULL && cont) {
  1547.     enbl = classPtr->enable;
  1548.     if (enbl != NULL) {
  1549.       enbl (a, setFlag, savePort);
  1550.       cont = FALSE;
  1551.     } else {
  1552.       classPtr = classPtr->ancestor;
  1553.     }
  1554.   }
  1555. }
  1556.  
  1557. extern void Nlm_DoDisable (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  1558.  
  1559. {
  1560.   Nlm_GphPrcsPtr  classPtr;
  1561.   Nlm_Boolean     cont;
  1562.   void            (*dsbl) PROTO((Nlm_GraphiC, Nlm_Boolean, Nlm_Boolean));
  1563.  
  1564.   cont = TRUE;
  1565.   classPtr = Nlm_GetClassPtr (a);
  1566.   while (classPtr != NULL && cont) {
  1567.     dsbl = classPtr->disable;
  1568.     if (dsbl != NULL) {
  1569.       dsbl (a, setFlag, savePort);
  1570.       cont = FALSE;
  1571.     } else {
  1572.       classPtr = classPtr->ancestor;
  1573.     }
  1574.   }
  1575. }
  1576.  
  1577. extern void Nlm_DoActivate (Nlm_GraphiC a, Nlm_Boolean savePort)
  1578.  
  1579. {
  1580.   void            (*actvate) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1581.   Nlm_Boolean     cont;
  1582.   Nlm_GphPrcsPtr  classPtr;
  1583.  
  1584.   cont = TRUE;
  1585.   classPtr = Nlm_GetClassPtr (a);
  1586.   while (classPtr != NULL && cont) {
  1587.     actvate = classPtr->activate;
  1588.     if (actvate != NULL) {
  1589.       actvate (a, savePort);
  1590.       cont = FALSE;
  1591.     } else {
  1592.       classPtr = classPtr->ancestor;
  1593.     }
  1594.   }
  1595. }
  1596.  
  1597. extern void Nlm_DoDeactivate (Nlm_GraphiC a, Nlm_Boolean savePort)
  1598.  
  1599. {
  1600.   Nlm_GphPrcsPtr  classPtr;
  1601.   Nlm_Boolean     cont;
  1602.   void            (*deactvate) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1603.  
  1604.   cont = TRUE;
  1605.   classPtr = Nlm_GetClassPtr (a);
  1606.   while (classPtr != NULL && cont) {
  1607.     deactvate = classPtr->deactivate;
  1608.     if (deactvate != NULL) {
  1609.       deactvate (a, savePort);
  1610.       cont = FALSE;
  1611.     } else {
  1612.       classPtr = classPtr->ancestor;
  1613.     }
  1614.   }
  1615. }
  1616.  
  1617. extern Nlm_Handle Nlm_DoRemove (Nlm_GraphiC a, Nlm_Boolean savePort)
  1618.  
  1619. {
  1620.   Nlm_GphPrcsPtr  classPtr;
  1621.   Nlm_Boolean     cont;
  1622.   void            (*rmv) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1623.  
  1624.   cont = TRUE;
  1625.   Nlm_DoHide (a, TRUE, savePort);
  1626.   classPtr = Nlm_GetClassPtr (a);
  1627.   while (classPtr != NULL && cont) {
  1628.     rmv = classPtr->remove;
  1629.     if (rmv != NULL) {
  1630.       rmv (a, savePort);
  1631.       cont = FALSE;
  1632.     } else {
  1633.       classPtr = classPtr->ancestor;
  1634.     }
  1635.     recentGraphic = NULL;
  1636.     recentBox = NULL;
  1637.   }
  1638.   return NULL;
  1639. }
  1640.  
  1641. extern void Nlm_DoReset (Nlm_GraphiC a, Nlm_Boolean savePort)
  1642.  
  1643. {
  1644.   Nlm_GphPrcsPtr  classPtr;
  1645.   Nlm_Boolean     cont;
  1646.   void            (*rst) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1647.  
  1648.   cont = TRUE;
  1649.   classPtr = Nlm_GetClassPtr (a);
  1650.   while (classPtr != NULL && cont) {
  1651.     rst = classPtr->reset;
  1652.     if (rst != NULL) {
  1653.       rst (a, TRUE);
  1654.       cont = FALSE;
  1655.     } else {
  1656.       classPtr = classPtr->ancestor;
  1657.     }
  1658.   }
  1659. }
  1660.  
  1661. extern void Nlm_DoSelect (Nlm_GraphiC a, Nlm_Boolean savePort)
  1662.  
  1663. {
  1664.   Nlm_GphPrcsPtr  classPtr;
  1665.   Nlm_Boolean     cont;
  1666.   void            (*sel) PROTO((Nlm_GraphiC, Nlm_Boolean));
  1667.  
  1668.   cont = TRUE;
  1669.   classPtr = Nlm_GetClassPtr (a);
  1670.   while (classPtr != NULL && cont) {
  1671.     sel = classPtr->select;
  1672.     if (sel != NULL) {
  1673.       sel (a, savePort);
  1674.       cont = FALSE;
  1675.     } else {
  1676.       classPtr = classPtr->ancestor;
  1677.     }
  1678.   }
  1679. }
  1680.  
  1681. extern Nlm_Int2 Nlm_CountItems (Nlm_Handle a)
  1682.  
  1683. {
  1684.   Nlm_GphPrcsPtr  classPtr;
  1685.   Nlm_Boolean     cont;
  1686.   Nlm_Int2        (*cntitm) PROTO((Nlm_GraphiC));
  1687.   Nlm_Int2        len;
  1688.  
  1689.   cont = TRUE;
  1690.   len = 0;
  1691.   classPtr = Nlm_GetClassPtr ((Nlm_GraphiC)a);
  1692.   while (classPtr != NULL && cont) {
  1693.     cntitm = classPtr->countItems;
  1694.     if (cntitm != NULL) {
  1695.       len = cntitm ((Nlm_GraphiC)a);
  1696.       cont = FALSE;
  1697.     } else {
  1698.       classPtr = classPtr->ancestor;
  1699.     }
  1700.   }
  1701.   return len;
  1702. }
  1703.  
  1704. extern Nlm_GraphiC Nlm_DoLinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt)
  1705.  
  1706. {
  1707.   Nlm_GphPrcsPtr  prntClassPtr;
  1708.   Nlm_Boolean     cont;
  1709.   Nlm_GraphiC     (*lnkIn) PROTO((Nlm_GraphiC, Nlm_GraphiC));
  1710.   Nlm_GraphiC     rsult;
  1711.  
  1712.   cont = TRUE;
  1713.   rsult = NULL;
  1714.   if (a != NULL && prnt != NULL) {
  1715.     cont = TRUE;
  1716.     prntClassPtr = Nlm_GetClassPtr (prnt);
  1717.     while (prntClassPtr != NULL && cont) {
  1718.       lnkIn = prntClassPtr->linkIn;
  1719.       if (lnkIn != NULL) {
  1720.         rsult = lnkIn (a, prnt);
  1721.         cont = FALSE;
  1722.       } else {
  1723.         prntClassPtr = prntClassPtr->ancestor;
  1724.       }
  1725.     }
  1726.   }
  1727.   return rsult;
  1728. }
  1729.  
  1730. extern void Nlm_DoAdjustPrnt (Nlm_GraphiC a, Nlm_RectPtr r,
  1731.                               Nlm_Boolean align, Nlm_Boolean savePort)
  1732.  
  1733. {
  1734.   void            (*adjst) PROTO((Nlm_GraphiC, Nlm_RectPtr, Nlm_Boolean, Nlm_Boolean));
  1735.   Nlm_Boolean     cont;
  1736.   Nlm_GraphiC     p;
  1737.   Nlm_GphPrcsPtr  prntClassPtr;
  1738.  
  1739.   cont = TRUE;
  1740.   if (a != NULL) {
  1741.     p = Nlm_GetParent (a);
  1742.     prntClassPtr = Nlm_GetClassPtr (p);
  1743.     while (prntClassPtr != NULL && cont) {
  1744.       adjst = prntClassPtr->adjustPrnt;
  1745.       if (adjst != NULL) {
  1746.         adjst (a, r, align, savePort);
  1747.         cont = FALSE;
  1748.       } else {
  1749.         prntClassPtr = prntClassPtr->ancestor;
  1750.       }
  1751.     }
  1752.   }
  1753. }
  1754.  
  1755. extern void Nlm_DoSetTitle (Nlm_GraphiC a, Nlm_Int2 item,
  1756.                             Nlm_CharPtr title, Nlm_Boolean savePort)
  1757.  
  1758. {
  1759.   Nlm_GphPrcsPtr  classPtr;
  1760.   Nlm_Boolean     cont;
  1761.   void            (*stttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, Nlm_Boolean));
  1762.  
  1763.   cont = TRUE;
  1764.   classPtr = Nlm_GetClassPtr (a);
  1765.   while (classPtr != NULL && cont) {
  1766.     stttl = classPtr->setTitle;
  1767.     if (stttl != NULL) {
  1768.       stttl (a, item, title, savePort);
  1769.       cont = FALSE;
  1770.     } else {
  1771.       classPtr = classPtr->ancestor;
  1772.     }
  1773.   }
  1774. }
  1775.  
  1776. extern void Nlm_DoGetTitle (Nlm_GraphiC a, Nlm_Int2 item,
  1777.                             Nlm_CharPtr title, Nlm_sizeT maxsize)
  1778.  
  1779. {
  1780.   Nlm_GphPrcsPtr  classPtr;
  1781.   Nlm_Boolean     cont;
  1782.   Nlm_Boolean     failed;
  1783.   void            (*gtttl) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_CharPtr, Nlm_sizeT));
  1784.  
  1785.   cont = TRUE;
  1786.   failed = TRUE;
  1787.   classPtr = Nlm_GetClassPtr (a);
  1788.   while (classPtr != NULL && cont) {
  1789.     gtttl = classPtr->getTitle;
  1790.     if (gtttl != NULL) {
  1791.       gtttl (a, item, title, maxsize);
  1792.       failed = FALSE;
  1793.       cont = FALSE;
  1794.     } else {
  1795.       classPtr = classPtr->ancestor;
  1796.     }
  1797.   }
  1798.   if (failed) {
  1799.     Nlm_StringNCpy (title, "", maxsize);
  1800.   }
  1801. }
  1802.  
  1803. extern void Nlm_DoSetValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort)
  1804.  
  1805. {
  1806.   Nlm_GphPrcsPtr  classPtr;
  1807.   Nlm_Boolean     cont;
  1808.   void            (*stval) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean));
  1809.  
  1810.   cont = TRUE;
  1811.   classPtr = Nlm_GetClassPtr (a);
  1812.   while (classPtr != NULL && cont) {
  1813.     stval = classPtr->setValue;
  1814.     if (stval != NULL) {
  1815.       stval (a, value, savePort);
  1816.       cont = FALSE;
  1817.     } else {
  1818.       classPtr = classPtr->ancestor;
  1819.     }
  1820.   }
  1821. }
  1822.  
  1823. extern Nlm_Int2 Nlm_DoGetValue (Nlm_GraphiC a)
  1824.  
  1825. {
  1826.   Nlm_GphPrcsPtr  classPtr;
  1827.   Nlm_Boolean     cont;
  1828.   Nlm_Int2        (*gtval) PROTO((Nlm_GraphiC));
  1829.   Nlm_Int2        value;
  1830.  
  1831.   cont = TRUE;
  1832.   value = 0;
  1833.   classPtr = Nlm_GetClassPtr (a);
  1834.   while (classPtr != NULL && cont) {
  1835.     gtval = classPtr->getValue;
  1836.     if (gtval != NULL) {
  1837.       value = gtval (a);
  1838.       cont = FALSE;
  1839.     } else {
  1840.       classPtr = classPtr->ancestor;
  1841.     }
  1842.   }
  1843.   return value;
  1844. }
  1845.  
  1846. extern void Nlm_DoSetStatus (Nlm_GraphiC a, Nlm_Int2 item,
  1847.                              Nlm_Boolean status, Nlm_Boolean savePort)
  1848.  
  1849. {
  1850.   Nlm_GphPrcsPtr  classPtr;
  1851.   Nlm_Boolean     cont;
  1852.   void            (*ststs) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Boolean, Nlm_Boolean));
  1853.  
  1854.   cont = TRUE;
  1855.   classPtr = Nlm_GetClassPtr (a);
  1856.   while (classPtr != NULL && cont) {
  1857.     ststs = classPtr->setStatus;
  1858.     if (ststs != NULL) {
  1859.       ststs (a, item, status, savePort);
  1860.       cont = FALSE;
  1861.     } else {
  1862.       classPtr = classPtr->ancestor;
  1863.     }
  1864.   }
  1865. }
  1866.  
  1867. extern Nlm_Boolean Nlm_DoGetStatus (Nlm_GraphiC a, Nlm_Int2 item)
  1868.  
  1869. {
  1870.   Nlm_GphPrcsPtr  classPtr;
  1871.   Nlm_Boolean     cont;
  1872.   Nlm_Boolean     (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2));
  1873.   Nlm_Boolean     val;
  1874.  
  1875.   cont = TRUE;
  1876.   val = FALSE;
  1877.   classPtr = Nlm_GetClassPtr (a);
  1878.   while (classPtr != NULL && cont) {
  1879.     gtsts = classPtr->getStatus;
  1880.     if (gtsts != NULL) {
  1881.       val = gtsts (a, item);
  1882.       cont = FALSE;
  1883.     } else {
  1884.       classPtr = classPtr->ancestor;
  1885.     }
  1886.   }
  1887.   return val;
  1888. }
  1889.  
  1890. extern void Nlm_DoSetOffset (Nlm_GraphiC a, Nlm_Int2 horiz,
  1891.                              Nlm_Int2 vert,Nlm_Boolean savePort)
  1892.  
  1893. {
  1894.   Nlm_GphPrcsPtr  classPtr;
  1895.   Nlm_Boolean     cont;
  1896.   void            (*stoff) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Boolean));
  1897.  
  1898.   cont = TRUE;
  1899.   classPtr = Nlm_GetClassPtr (a);
  1900.   while (classPtr != NULL && cont) {
  1901.     stoff = classPtr->setOffset;
  1902.     if (stoff != NULL) {
  1903.       stoff (a, horiz, vert, savePort);
  1904.       cont = FALSE;
  1905.     } else {
  1906.       classPtr = classPtr->ancestor;
  1907.     }
  1908.   }
  1909. }
  1910.  
  1911. extern void Nlm_DoGetOffset (Nlm_GraphiC a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
  1912.  
  1913. {
  1914.   Nlm_GphPrcsPtr  classPtr;
  1915.   Nlm_Boolean     cont;
  1916.   Nlm_Boolean     failed;
  1917.   void            (*gtoff) PROTO((Nlm_GraphiC, Nlm_Int2Ptr, Nlm_Int2Ptr));
  1918.  
  1919.   cont = TRUE;
  1920.   failed = TRUE;
  1921.   classPtr = Nlm_GetClassPtr (a);
  1922.   while (classPtr != NULL && cont) {
  1923.     gtoff = classPtr->getOffset;
  1924.     if (gtoff != NULL) {
  1925.       gtoff (a, horiz, vert);
  1926.       failed = FALSE;
  1927.       cont = FALSE;
  1928.     } else {
  1929.       classPtr = classPtr->ancestor;
  1930.     }
  1931.   }
  1932.   if (failed) {
  1933.     if (horiz != NULL) {
  1934.       *horiz = 0;
  1935.     }
  1936.     if (vert != NULL) {
  1937.       *vert = 0;
  1938.     }
  1939.   }
  1940. }
  1941.  
  1942. extern void Nlm_DoSetPosition (Nlm_GraphiC a, Nlm_RectPtr r, Nlm_Boolean savePort)
  1943.  
  1944. {
  1945.   Nlm_GphPrcsPtr  classPtr;
  1946.   Nlm_Boolean     cont;
  1947.   void            (*stpos) PROTO((Nlm_GraphiC, Nlm_RectPtr, Nlm_Boolean));
  1948.  
  1949.   cont = TRUE;
  1950.   classPtr = Nlm_GetClassPtr (a);
  1951.   while (classPtr != NULL && cont) {
  1952.     stpos = classPtr->setPosition;
  1953.     if (stpos != NULL) {
  1954.       stpos (a, r, savePort);
  1955.       cont = FALSE;
  1956.     } else {
  1957.       classPtr = classPtr->ancestor;
  1958.     }
  1959.   }
  1960. }
  1961.  
  1962. extern void Nlm_DoGetPosition (Nlm_GraphiC a, Nlm_RectPtr r)
  1963.  
  1964. {
  1965.   Nlm_GphPrcsPtr  classPtr;
  1966.   Nlm_Boolean     cont;
  1967.   Nlm_Boolean     failed;
  1968.   void            (*gtpos) PROTO((Nlm_GraphiC, Nlm_RectPtr));
  1969.  
  1970.   cont = TRUE;
  1971.   failed = TRUE;
  1972.   classPtr = Nlm_GetClassPtr (a);
  1973.   while (classPtr != NULL && cont) {
  1974.     gtpos = classPtr->getPosition;
  1975.     if (gtpos != NULL) {
  1976.       gtpos (a, r);
  1977.       failed = FALSE;
  1978.       cont = FALSE;
  1979.     } else {
  1980.       classPtr = classPtr->ancestor;
  1981.     }
  1982.   }
  1983.   if (failed) {
  1984.     if (r != NULL) {
  1985.       Nlm_LoadRect (r, 0, 0, 0, 0);
  1986.     }
  1987.   }
  1988. }
  1989.  
  1990. extern void Nlm_DoSetRange (Nlm_GraphiC a, Nlm_Int2 pgUp,
  1991.                             Nlm_Int2 pgDn, Nlm_Int2 max,
  1992.                             Nlm_Boolean savePort)
  1993.  
  1994. {
  1995.   Nlm_GphPrcsPtr  classPtr;
  1996.   Nlm_Boolean     cont;
  1997.   void            (*rng) PROTO((Nlm_GraphiC, Nlm_Int2, Nlm_Int2, Nlm_Int2, Nlm_Boolean));
  1998.  
  1999.  
  2000.   cont = TRUE;
  2001.   classPtr = Nlm_GetClassPtr (a);
  2002.   while (classPtr != NULL && cont) {
  2003.     rng = classPtr->setRange;
  2004.     if (rng != NULL) {
  2005.       rng (a, pgUp, pgDn, max, savePort);
  2006.       cont = FALSE;
  2007.     } else {
  2008.       classPtr = classPtr->ancestor;
  2009.     }
  2010.   }
  2011. }
  2012.  
  2013. extern Nlm_GraphiC Nlm_DoGainFocus (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort)
  2014.  
  2015. {
  2016.   Nlm_GphPrcsPtr  classPtr;
  2017.   Nlm_Boolean     cont;
  2018.   Nlm_GraphiC     rsult;
  2019.   Nlm_GraphiC     (*gainFcs) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean));
  2020.  
  2021.   cont = TRUE;
  2022.   rsult = NULL;
  2023.   classPtr = Nlm_GetClassPtr (a);
  2024.   while (classPtr != NULL && cont) {
  2025.     gainFcs = classPtr->gainFocus;
  2026.     if (gainFcs != NULL) {
  2027.       rsult = gainFcs (a, ch, savePort);
  2028.       cont = FALSE;
  2029.     } else {
  2030.       classPtr = classPtr->ancestor;
  2031.     }
  2032.   }
  2033.   return rsult;
  2034. }
  2035.  
  2036. extern void Nlm_DoLoseFocus (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2037.  
  2038. {
  2039.   Nlm_GphPrcsPtr  classPtr;
  2040.   Nlm_Boolean     cont;
  2041.   void            (*loseFcs) PROTO((Nlm_GraphiC, Nlm_GraphiC, Nlm_Boolean));
  2042.  
  2043.   cont = TRUE;
  2044.   classPtr = Nlm_GetClassPtr (a);
  2045.   while (classPtr != NULL && cont) {
  2046.     loseFcs = classPtr->loseFocus;
  2047.     if (loseFcs != NULL) {
  2048.       loseFcs (a, excpt, savePort);
  2049.       cont = FALSE;
  2050.     } else {
  2051.       classPtr = classPtr->ancestor;
  2052.     }
  2053.   }
  2054. }
  2055.  
  2056. extern void Nlm_DoSendChar (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort)
  2057.  
  2058. {
  2059.   Nlm_GphPrcsPtr  classPtr;
  2060.   Nlm_Boolean     cont;
  2061.   void            (*sendCh) PROTO((Nlm_GraphiC, Nlm_Char, Nlm_Boolean));
  2062.  
  2063.   cont = TRUE;
  2064.   classPtr = Nlm_GetClassPtr (a);
  2065.   while (classPtr != NULL && cont) {
  2066.     sendCh = classPtr->sendChar;
  2067.     if (sendCh != NULL) {
  2068.       sendCh (a, ch, savePort);
  2069.       cont = FALSE;
  2070.     } else {
  2071.       classPtr = classPtr->ancestor;
  2072.     }
  2073.   }
  2074. }
  2075.  
  2076. static Nlm_GraphiC Nlm_CheckThisLevel (Nlm_GraphiC a, Nlm_Char ch)
  2077.  
  2078. {
  2079.   Nlm_GraphiC  p;
  2080.   Nlm_GraphiC  q;
  2081.  
  2082.   q = NULL;
  2083.   p = a;
  2084.   while (p != NULL && q == NULL) {
  2085.     q = Nlm_DoGainFocus (p, ch, FALSE);
  2086.     p = Nlm_GetNext (p);
  2087.   }
  2088.   return q;
  2089. }
  2090.  
  2091. extern void Nlm_DoSendFocus (Nlm_GraphiC a, Nlm_Char ch)
  2092.  
  2093. {
  2094.   Nlm_GraphiC   cur;
  2095.   Nlm_GraphiC   nxt;
  2096.   Nlm_GraphiC   q;
  2097.  
  2098.   q = NULL;
  2099.   nxt = (Nlm_GraphiC) a;
  2100.   while (q == NULL && nxt != NULL) {
  2101.     cur = nxt;
  2102.     nxt = Nlm_GetParent (cur);
  2103.     if (nxt != NULL) {
  2104.       cur = Nlm_GetNext (cur);
  2105.     }
  2106.     q = Nlm_CheckThisLevel (cur, ch);
  2107.   }
  2108. }
  2109.  
  2110. extern void Nlm_DoAction (Nlm_GraphiC a)
  2111.  
  2112. {
  2113.   void             (*act) PROTO((Nlm_GraphiC));
  2114.   Nlm_GraphicData  gdata;
  2115.  
  2116.   if (a != NULL) {
  2117.     Nlm_GetGraphicData (a, &gdata);
  2118.     act = gdata.action;
  2119.     if (act != NULL) {
  2120.       act (a);
  2121.     }
  2122.   }
  2123. }
  2124.  
  2125. extern void Nlm_Show (Nlm_Handle a)
  2126.  
  2127. {
  2128.   Nlm_DoShow ((Nlm_GraphiC) a, TRUE, TRUE);
  2129. }
  2130.  
  2131. extern void Nlm_Hide (Nlm_Handle a)
  2132.  
  2133. {
  2134.   Nlm_DoHide ((Nlm_GraphiC) a, TRUE, TRUE);
  2135. }
  2136.  
  2137. extern void Nlm_Enable (Nlm_Handle a)
  2138.  
  2139. {
  2140.   Nlm_DoEnable ((Nlm_GraphiC) a, TRUE, TRUE);
  2141. }
  2142.  
  2143. extern void Nlm_Disable (Nlm_Handle a)
  2144.  
  2145. {
  2146.   Nlm_DoDisable ((Nlm_GraphiC) a, TRUE, TRUE);
  2147. }
  2148.  
  2149. extern Nlm_Handle Nlm_Remove (Nlm_Handle a)
  2150.  
  2151. {
  2152.   return Nlm_DoRemove ((Nlm_GraphiC) a, TRUE);
  2153. }
  2154.  
  2155. extern void Nlm_Reset (Nlm_Handle a)
  2156.  
  2157. {
  2158.   Nlm_DoReset ((Nlm_GraphiC) a, TRUE);
  2159. }
  2160.  
  2161. extern void Nlm_Select (Nlm_Handle a)
  2162.  
  2163. {
  2164.   Nlm_DoSelect ((Nlm_GraphiC) a, TRUE);
  2165. }
  2166.  
  2167. extern void Nlm_SetTitle (Nlm_Handle a, Nlm_CharPtr title)
  2168.  
  2169. {
  2170.   Nlm_DoSetTitle ((Nlm_GraphiC) a, 0, title, TRUE);
  2171. }
  2172.  
  2173. extern void Nlm_GetTitle (Nlm_Handle a, Nlm_CharPtr title, Nlm_sizeT maxsize)
  2174.  
  2175. {
  2176.   Nlm_DoGetTitle ((Nlm_GraphiC) a, 0, title, maxsize);
  2177. }
  2178.  
  2179. extern void Nlm_SetValue (Nlm_Handle a, Nlm_Int2 value)
  2180.  
  2181. {
  2182.   Nlm_DoSetValue ((Nlm_GraphiC) a, value, TRUE);
  2183. }
  2184.  
  2185. extern Nlm_Int2 Nlm_GetValue (Nlm_Handle a)
  2186.  
  2187. {
  2188.   return (Nlm_DoGetValue ((Nlm_GraphiC) a));
  2189. }
  2190.  
  2191. extern void Nlm_SetStatus (Nlm_Handle a, Nlm_Boolean status)
  2192.  
  2193. {
  2194.   Nlm_DoSetStatus ((Nlm_GraphiC) a, 0, status, TRUE);
  2195. }
  2196.  
  2197. extern Nlm_Boolean Nlm_GetStatus (Nlm_Handle a)
  2198.  
  2199. {
  2200.   return (Nlm_DoGetStatus ((Nlm_GraphiC) a, 0));
  2201. }
  2202.  
  2203. extern void Nlm_SetOffset (Nlm_Handle a, Nlm_Int2 horiz, Nlm_Int2 vert)
  2204.  
  2205. {
  2206.   Nlm_DoSetOffset ((Nlm_GraphiC) a, horiz, vert, TRUE);
  2207. }
  2208.  
  2209. extern void Nlm_GetOffset (Nlm_Handle a, Nlm_Int2Ptr horiz, Nlm_Int2Ptr vert)
  2210.  
  2211. {
  2212.   Nlm_DoGetOffset ((Nlm_GraphiC) a, horiz, vert);
  2213. }
  2214.  
  2215. extern void Nlm_SetPosition (Nlm_Handle a, Nlm_RectPtr r)
  2216.  
  2217. {
  2218.   Nlm_DoSetPosition ((Nlm_GraphiC) a, r, TRUE);
  2219. }
  2220.  
  2221. extern void Nlm_GetPosition (Nlm_Handle a, Nlm_RectPtr r)
  2222.  
  2223. {
  2224.   Nlm_DoGetPosition ((Nlm_GraphiC) a, r);
  2225. }
  2226.  
  2227. extern void Nlm_SetRange (Nlm_Handle a, Nlm_Int2 pgUp,
  2228.                           Nlm_Int2 pgDn, Nlm_Int2 max)
  2229.  
  2230. {
  2231.   Nlm_DoSetRange ((Nlm_GraphiC) a, pgUp, pgDn, max, TRUE);
  2232. }
  2233.  
  2234. extern void Nlm_SetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title)
  2235.  
  2236. {
  2237.   Nlm_DoSetTitle ((Nlm_GraphiC) a, item, title, TRUE);
  2238. }
  2239.  
  2240. extern void Nlm_GetItemTitle (Nlm_Handle a, Nlm_Int2 item, Nlm_CharPtr title, Nlm_sizeT maxsize)
  2241.  
  2242. {
  2243.   Nlm_DoGetTitle ((Nlm_GraphiC) a, item, title, maxsize);
  2244. }
  2245.  
  2246. extern void Nlm_SetItemStatus (Nlm_Handle a, Nlm_Int2 item, Nlm_Boolean status)
  2247.  
  2248. {
  2249.   Nlm_DoSetStatus ((Nlm_GraphiC) a, item, status, TRUE);
  2250. }
  2251.  
  2252. extern Nlm_Boolean Nlm_GetItemStatus (Nlm_Handle a, Nlm_Int2 item)
  2253.  
  2254. {
  2255.   return (Nlm_DoGetStatus ((Nlm_GraphiC) a, item));
  2256. }
  2257.  
  2258. extern Nlm_Int2 Nlm_GetNextItem (Nlm_Handle a, Nlm_Int2 prev)
  2259.  
  2260. {
  2261.   Nlm_GphPrcsPtr  classPtr;
  2262.   Nlm_Int2        (*cntitm) PROTO((Nlm_GraphiC));
  2263.   Nlm_Int2        count;
  2264.   Nlm_Boolean     (*gtsts) PROTO((Nlm_GraphiC, Nlm_Int2));
  2265.   Nlm_Boolean     found;
  2266.   Nlm_Int2        rsult;
  2267.  
  2268.   rsult = 0;
  2269.   if (a != NULL && prev >= 0) {
  2270.     classPtr = Nlm_GetClassPtr ((Nlm_GraphiC) a);
  2271.     if (classPtr != NULL) {
  2272.       cntitm = classPtr->countItems;
  2273.       gtsts = classPtr->getStatus;
  2274.       if (cntitm != NULL && gtsts != NULL) {
  2275.         count = cntitm ((Nlm_GraphiC) a);
  2276.         found = FALSE;
  2277.         while (prev < count && (! found)) {
  2278.           prev++;
  2279.           found = gtsts ((Nlm_GraphiC) a, prev);
  2280.         }
  2281.         if (found) {
  2282.           rsult = prev;
  2283.         }
  2284.       }
  2285.     }
  2286.   }
  2287.   return rsult;
  2288. }
  2289.  
  2290. extern void Nlm_ClearItemsInGroup (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  2291.  
  2292. {
  2293.   Nlm_GraphiC  g;
  2294.  
  2295.   if (a != NULL) {
  2296.     g = Nlm_GetChild (a);
  2297.     while (g != NULL) {
  2298.       if (g != excpt) {
  2299.         Nlm_DoSetStatus (g, 0, FALSE, savePort);
  2300.       }
  2301.       g = Nlm_GetNext (g);
  2302.     }
  2303.   }
  2304. }
  2305.  
  2306. extern Nlm_Int2 Nlm_CountGroupItems (Nlm_GraphiC a)
  2307.  
  2308. {
  2309.   Nlm_GraphiC  g;
  2310.   Nlm_Int2     i;
  2311.  
  2312.   i = 0;
  2313.   if (a != NULL) {
  2314.     g = Nlm_GetChild (a);
  2315.     while (g != NULL) {
  2316.       i++;
  2317.       g = Nlm_GetNext (g);
  2318.     }
  2319.   }
  2320.   return i;
  2321. }
  2322.  
  2323. extern Nlm_GraphiC Nlm_LinkIn (Nlm_GraphiC a, Nlm_GraphiC prnt)
  2324.  
  2325. {
  2326.   Nlm_GraphiC  first;
  2327.   Nlm_GraphiC  g;
  2328.   Nlm_GphPtr   gp;
  2329.   Nlm_GraphiC  last;
  2330.   Nlm_GphPtr   lastp;
  2331.   Nlm_GraphiC  p;
  2332.   Nlm_GphPtr   prntp;
  2333.  
  2334.   if (prnt != NULL) {
  2335.     g = (Nlm_GraphiC) a;
  2336.     prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2337.     first = prntp->children;
  2338.     last = prntp->lastChild;
  2339.     Nlm_HandUnlock (prnt);
  2340.     if (last != NULL) {
  2341.       lastp = (Nlm_GphPtr) Nlm_HandLock (last);
  2342.       lastp->next = g;
  2343.       Nlm_HandUnlock (last);
  2344.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2345.       prntp->lastChild = g;
  2346.       Nlm_HandUnlock (prnt);
  2347.     } else if (first != NULL) {
  2348.       p = first;
  2349.       while (p != NULL) {
  2350.         last = p;
  2351.         p = Nlm_GetNext (p);
  2352.       }
  2353.       lastp = (Nlm_GphPtr) Nlm_HandLock (last);
  2354.       lastp->next = g;
  2355.       Nlm_HandUnlock (last);
  2356.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2357.       prntp->lastChild = g;
  2358.       Nlm_HandUnlock (prnt);
  2359.     } else {
  2360.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2361.       prntp->children = g;
  2362.       prntp->lastChild = g;
  2363.       Nlm_HandUnlock (prnt);
  2364.     }
  2365.     gp = (Nlm_GphPtr) Nlm_HandLock (g);
  2366.     gp->next = NULL;
  2367.     gp->parent = prnt;
  2368.     gp->children = NULL;
  2369.     gp->lastChild = NULL;
  2370.     Nlm_HandUnlock (g);
  2371.   }
  2372.   recentGraphic = NULL;
  2373.   recentBox = NULL;
  2374.   return a;
  2375. }
  2376.  
  2377. extern void Nlm_LoadAction (Nlm_GraphiC a, Nlm_ActnProc actnProc)
  2378.  
  2379. {
  2380.   Nlm_GraphicData  gdata;
  2381.  
  2382.   if (a != NULL) {
  2383.     Nlm_GetGraphicData (a, &gdata);
  2384.     gdata.action = actnProc;
  2385.     Nlm_SetGraphicData (a, &gdata);
  2386.   }
  2387. }
  2388.  
  2389. extern void Nlm_LoadGraphicData (Nlm_GraphiC a, Nlm_GraphiC nxt,
  2390.                                  Nlm_GraphiC prnt, Nlm_GraphiC chld,
  2391.                                  Nlm_GraphiC lstchd, Nlm_GphPrcs PNTR classPtr,
  2392.                                  Nlm_ActnProc actnProc, Nlm_RectPtr r,
  2393.                                  Nlm_Boolean enabl, Nlm_Boolean vis)
  2394.  
  2395. {
  2396.   Nlm_GphPtr  ptr;
  2397.  
  2398.   if (a != NULL) {
  2399.     ptr = (Nlm_GphPtr) Nlm_HandLock (a);
  2400.     ptr->next = nxt;
  2401.     ptr->parent = prnt;
  2402.     ptr->children = chld;
  2403.     ptr->lastChild = lstchd;
  2404.     ptr->classptr = classPtr;
  2405.     ptr->action = actnProc;
  2406.     if (r != NULL) {
  2407.       ptr->rect = *r;
  2408.     } else {
  2409.       Nlm_LoadRect (&(ptr->rect), 0, 0, 0, 0);
  2410.     }
  2411.     ptr->enabled = enabl;
  2412.     ptr->visible = vis;
  2413.     Nlm_HandUnlock (a);
  2414.     recentGraphic = NULL;
  2415.   }
  2416. }
  2417.  
  2418. extern void Nlm_LoadBoxData (Nlm_BoX a, Nlm_PoinT nxt,
  2419.                              Nlm_PoinT lmt, Nlm_PoinT rst,
  2420.                              Nlm_Int2 top, Nlm_Int2 ncol,
  2421.                              Nlm_Int2 xMrg, Nlm_Int2 yMrg,
  2422.                              Nlm_Int2 xSpc, Nlm_Int2 ySpc,
  2423.                              Nlm_Int2 wid, Nlm_Int2 hgt)
  2424.  
  2425. {
  2426.   Nlm_BoxPtr   bp;
  2427.   Nlm_BoxData  PNTR bptr;
  2428.  
  2429.   if (a != NULL) {
  2430.     bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2431.     bptr = &(bp->box);
  2432.     bptr->nextPoint = nxt;
  2433.     bptr->limitPoint = lmt;
  2434.     bptr->resetPoint = rst;
  2435.     bptr->topRow = top;
  2436.     bptr->nextCol = ncol;
  2437.     bptr->xMargin = xMrg;
  2438.     bptr->yMargin = yMrg;
  2439.     bptr->xSpacing = xSpc;
  2440.     bptr->ySpacing = ySpc;
  2441.     bptr->boxWidth = wid;
  2442.     bptr->boxHeight = hgt;
  2443.     Nlm_HandUnlock (a);
  2444.     recentBox = NULL;
  2445.   }
  2446. }
  2447.  
  2448. extern void Nlm_SetAction (Nlm_Handle a, Nlm_ActnProc actn)
  2449.  
  2450. {
  2451.   Nlm_GraphiC      g;
  2452.   Nlm_GraphicData  gdata;
  2453.  
  2454.   if (a != NULL) {
  2455.     g = (Nlm_GraphiC) a;
  2456.     if (g != NULL) {
  2457.       Nlm_GetGraphicData (g, &gdata);
  2458.       gdata.action = actn;
  2459.       Nlm_SetGraphicData (g, &gdata);
  2460.     }
  2461.   }
  2462. }
  2463.  
  2464. extern Nlm_GraphiC Nlm_CreateLink (Nlm_GraphiC prnt, Nlm_RectPtr r,
  2465.                                    Nlm_Int2 recordSize, Nlm_GphPrcs PNTR classPtr)
  2466.  
  2467. {
  2468.   Nlm_GraphiC  a;
  2469.   Nlm_GraphiC  rsult;
  2470.  
  2471.   rsult = NULL;
  2472.   a = NULL;
  2473.   if (prnt != NULL) {
  2474.     a = (Nlm_GraphiC) Nlm_HandNew (recordSize);
  2475.     if (a != NULL) {
  2476.       Nlm_LoadGraphicData (a, NULL, prnt, NULL, NULL, classPtr,
  2477.                            NULL, r, TRUE, FALSE);
  2478.       rsult = Nlm_DoLinkIn (a, prnt);
  2479.       if (rsult != NULL) {
  2480.         if (Nlm_nextIdNumber < 32767) {
  2481.           Nlm_nextIdNumber++;
  2482.         }
  2483.       } else {
  2484.         Nlm_HandFree (a);
  2485.       }
  2486.     }
  2487.   }
  2488.   return rsult;
  2489. }
  2490.  
  2491. extern void Nlm_RemoveLink (Nlm_GraphiC a)
  2492.  
  2493. {
  2494.   Nlm_GraphiC  first;
  2495.   Nlm_GraphiC  g;
  2496.   Nlm_GraphiC  n;
  2497.   Nlm_GraphiC  p;
  2498.   Nlm_GraphiC  prnt;
  2499.   Nlm_GphPtr   prntp;
  2500.   Nlm_GraphiC  q;
  2501.   Nlm_GphPtr   qp;
  2502.  
  2503.   if (a != NULL) {
  2504.     g = (Nlm_GraphiC) a;
  2505.     prnt = Nlm_GetParent (g);
  2506.     first = Nlm_GetChild (prnt);
  2507.     if (g == first) {
  2508.       n = Nlm_GetNext (g);
  2509.       prntp = (Nlm_GphPtr) Nlm_HandLock (prnt);
  2510.       prntp->children = n;
  2511.       if (prntp->lastChild == g) {
  2512.         prntp->lastChild = NULL;
  2513.       }
  2514.       Nlm_HandUnlock (prnt);
  2515.     } else {
  2516.       p = first;
  2517.       q = NULL; /* dgg: bug fix for when p==NULL*/
  2518.       while (p != NULL && p != g) {
  2519.         q = p;
  2520.         p = Nlm_GetNext (p);
  2521.       }
  2522.       if (q != NULL) {
  2523.         n = Nlm_GetNext (g);
  2524.         qp = (Nlm_GphPtr) Nlm_HandLock (q);
  2525.         qp->next = n;
  2526.         Nlm_HandUnlock (q);
  2527.       }
  2528.     }
  2529.     Nlm_HandFree (g);
  2530.   }
  2531.   recentGraphic = NULL;
  2532.   recentBox = NULL;
  2533. }
  2534.  
  2535. extern Nlm_GraphiC Nlm_FindItem (Nlm_GraphiC a, Nlm_Int2 item)
  2536.  
  2537. {
  2538.   Nlm_GraphiC  g;
  2539.  
  2540.   g = NULL;
  2541.   if (a != NULL && item > 0) {
  2542.     g = Nlm_GetChild (a);
  2543.     while (g != NULL && item > 1) {
  2544.       item--;
  2545.       g = Nlm_GetNext (g);
  2546.     }
  2547.   }
  2548.   return g;
  2549. }
  2550.  
  2551. extern Nlm_Int2 Nlm_GetItemIndex (Nlm_GraphiC a)
  2552.  
  2553. {
  2554.   Nlm_GraphiC  g;
  2555.   Nlm_Int2     index;
  2556.   Nlm_Int2     rsult;
  2557.  
  2558.   rsult = 0;
  2559.   if (a != NULL) {
  2560.     index = 1;
  2561.     g = Nlm_GetChild (a);
  2562.     while (g != NULL && g != a) {
  2563.       index++;
  2564.       g = Nlm_GetNext (g);
  2565.     }
  2566.     if (g == a) {
  2567.       rsult = index;
  2568.     } else {
  2569.       rsult = 0;
  2570.     }
  2571.   }
  2572.   return rsult;
  2573. }
  2574.  
  2575. extern Nlm_Boolean Nlm_GetAllParentsEnabled (Nlm_GraphiC a)
  2576.  
  2577. {
  2578.   Nlm_GraphiC  p;
  2579.  
  2580.   p = NULL;
  2581.   if (a != NULL) {
  2582.     p = Nlm_GetParent (a);
  2583.     while (p != NULL && Nlm_GetEnabled (p)) {
  2584.       p = Nlm_GetParent (p);
  2585.     }
  2586.   }
  2587.   return (Nlm_Boolean) (p == NULL);
  2588. }
  2589.  
  2590. extern Nlm_Boolean Nlm_AllParentsEnabled (Nlm_Handle a)
  2591.  
  2592. {
  2593.   return Nlm_GetAllParentsEnabled ((Nlm_GraphiC) a);
  2594. }
  2595.  
  2596. extern Nlm_Boolean Nlm_AllParentsButWindowVisible (Nlm_GraphiC a)
  2597.  
  2598. {
  2599.   Nlm_GraphiC  p;
  2600.  
  2601.   p = NULL;
  2602.   if (a != NULL) {
  2603.     p = Nlm_GetParent (a);
  2604.     while (p != NULL && Nlm_GetVisible (p)) {
  2605.       p = Nlm_GetParent (p);
  2606.     }
  2607.   }
  2608.   return (Nlm_Boolean) (p == NULL || Nlm_GetParent (p) == NULL);
  2609. }
  2610.  
  2611. extern Nlm_Boolean Nlm_GetAllParentsVisible (Nlm_GraphiC a)
  2612.  
  2613. {
  2614.   Nlm_GraphiC  p;
  2615.  
  2616.   p = NULL;
  2617.   if (a != NULL) {
  2618.     p = Nlm_GetParent (a);
  2619.     while (p != NULL && Nlm_GetVisible (p)) {
  2620.       p = Nlm_GetParent (p);
  2621.     }
  2622.   }
  2623.   return (Nlm_Boolean) (p == NULL);
  2624. }
  2625.  
  2626. extern Nlm_Boolean Nlm_AllParentsVisible (Nlm_Handle a)
  2627.  
  2628. {
  2629.   return Nlm_GetAllParentsVisible ((Nlm_GraphiC) a);
  2630. }
  2631.  
  2632. extern void Nlm_SetNext (Nlm_GraphiC a, Nlm_GraphiC nxt)
  2633.  
  2634. {
  2635.   Nlm_GraphicData  gdata;
  2636.  
  2637.   if (a != NULL) {
  2638.     Nlm_GetGraphicData (a, &gdata);
  2639.     gdata.next = nxt;
  2640.     Nlm_SetGraphicData (a, &gdata);
  2641.   }
  2642. }
  2643.  
  2644. extern Nlm_GraphiC Nlm_GetNext (Nlm_GraphiC a)
  2645.  
  2646. {
  2647.   Nlm_GraphicData  gdata;
  2648.   Nlm_GraphiC      rsult;
  2649.  
  2650.   rsult = NULL;
  2651.   if (a != NULL) {
  2652.     Nlm_GetGraphicData (a, &gdata);
  2653.     rsult = gdata.next;
  2654.   }
  2655.   return rsult;
  2656. }
  2657.  
  2658. extern void Nlm_SetParent (Nlm_GraphiC a, Nlm_GraphiC prnt)
  2659.  
  2660. {
  2661.   Nlm_GraphicData  gdata;
  2662.  
  2663.   if (a != NULL) {
  2664.     Nlm_GetGraphicData (a, &gdata);
  2665.     gdata.parent = prnt;
  2666.     Nlm_SetGraphicData (a, &gdata);
  2667.   }
  2668. }
  2669.  
  2670. extern Nlm_GraphiC Nlm_GetParent (Nlm_GraphiC a)
  2671.  
  2672. {
  2673.   Nlm_GraphicData  gdata;
  2674.   Nlm_GraphiC      rsult;
  2675.  
  2676.   rsult = NULL;
  2677.   if (a != NULL) {
  2678.     Nlm_GetGraphicData (a, &gdata);
  2679.     rsult = gdata.parent;
  2680.   }
  2681.   return rsult;
  2682. }
  2683.  
  2684. extern Nlm_Handle Nlm_Parent (Nlm_Handle a)
  2685.  
  2686. {
  2687.   return Nlm_GetParent ((Nlm_GraphiC) a);
  2688. }
  2689.  
  2690. extern void Nlm_SetChild (Nlm_GraphiC a, Nlm_GraphiC chld)
  2691.  
  2692. {
  2693.   Nlm_GraphicData  gdata;
  2694.  
  2695.   if (a != NULL) {
  2696.     Nlm_GetGraphicData (a, &gdata);
  2697.     gdata.children = chld;
  2698.     Nlm_SetGraphicData (a, &gdata);
  2699.   }
  2700. }
  2701.  
  2702. extern Nlm_GraphiC Nlm_GetChild (Nlm_GraphiC a)
  2703.  
  2704. {
  2705.   Nlm_GraphicData  gdata;
  2706.   Nlm_GraphiC      rsult;
  2707.  
  2708.   rsult = NULL;
  2709.   if (a != NULL) {
  2710.     Nlm_GetGraphicData (a, &gdata);
  2711.     rsult = gdata.children;
  2712.   }
  2713.   return rsult;
  2714. }
  2715.  
  2716. extern void Nlm_SetRect (Nlm_GraphiC a, Nlm_RectPtr r)
  2717.  
  2718. {
  2719.   Nlm_GraphicData  gdata;
  2720.  
  2721.   if (a != NULL && r != NULL) {
  2722.     Nlm_GetGraphicData (a, &gdata);
  2723.     gdata.rect = *r;
  2724.     Nlm_SetGraphicData (a, &gdata);
  2725.   }
  2726. }
  2727.  
  2728. extern void Nlm_GetRect (Nlm_GraphiC a, Nlm_RectPtr r)
  2729.  
  2730. {
  2731.   Nlm_GraphicData  gdata;
  2732.  
  2733.   if (a != NULL && r != NULL) {
  2734.     Nlm_GetGraphicData (a, &gdata);
  2735.     *r = gdata.rect;
  2736.   }
  2737. }
  2738.  
  2739. extern void Nlm_ObjectRect (Nlm_Handle a, Nlm_RectPtr r)
  2740.  
  2741. {
  2742.   Nlm_GetRect ((Nlm_GraphiC) a, r);
  2743. }
  2744.  
  2745. extern void Nlm_InvalObject (Nlm_Handle a)
  2746.  
  2747. {
  2748.   Nlm_RecT  r;
  2749.  
  2750.   if (a != NULL) {
  2751.     Nlm_GetRect ((Nlm_GraphiC) a, &r);
  2752.     Nlm_InsetRect (&r, -1, -1);
  2753.     Nlm_InvalRect (&r);
  2754.   }
  2755. }
  2756.  
  2757. extern void Nlm_SetEnabled (Nlm_GraphiC a, Nlm_Boolean enabld)
  2758.  
  2759. {
  2760.   Nlm_GraphicData  gdata;
  2761.  
  2762.   if (a != NULL) {
  2763.     Nlm_GetGraphicData (a, &gdata);
  2764.     gdata.enabled = enabld;
  2765.     Nlm_SetGraphicData (a, &gdata);
  2766.   }
  2767. }
  2768.  
  2769. extern Nlm_Boolean Nlm_GetEnabled (Nlm_GraphiC a)
  2770.  
  2771. {
  2772.   Nlm_GraphicData  gdata;
  2773.   Nlm_Boolean      rsult;
  2774.  
  2775.   rsult = FALSE;
  2776.   if (a != NULL) {
  2777.     Nlm_GetGraphicData (a, &gdata);
  2778.     rsult = gdata.enabled;
  2779.   }
  2780.   return rsult;
  2781. }
  2782.  
  2783. extern Nlm_Boolean Nlm_Enabled (Nlm_Handle a)
  2784.  
  2785. {
  2786.   return Nlm_GetEnabled ((Nlm_GraphiC) a);
  2787. }
  2788.  
  2789. extern void Nlm_SetVisible (Nlm_GraphiC a, Nlm_Boolean visibl)
  2790.  
  2791. {
  2792.   Nlm_GraphicData  gdata;
  2793.  
  2794.   if (a != NULL) {
  2795.     Nlm_GetGraphicData (a, &gdata);
  2796.     gdata.visible = visibl;
  2797.     Nlm_SetGraphicData (a, &gdata);
  2798.   }
  2799. }
  2800.  
  2801. extern Nlm_Boolean Nlm_GetVisible (Nlm_GraphiC a)
  2802.  
  2803. {
  2804.   Nlm_GraphicData  gdata;
  2805.   Nlm_Boolean      rsult;
  2806.  
  2807.   rsult = FALSE;
  2808.   if (a != NULL) {
  2809.     Nlm_GetGraphicData (a, &gdata);
  2810.     rsult = gdata.visible;
  2811.   }
  2812.   return rsult;
  2813. }
  2814.  
  2815. extern Nlm_Boolean Nlm_Visible (Nlm_Handle a)
  2816.  
  2817. {
  2818.   return Nlm_GetVisible ((Nlm_GraphiC) a);
  2819. }
  2820.  
  2821. extern void Nlm_SetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata)
  2822.  
  2823. {
  2824.   Nlm_GphPtr  gp;
  2825.  
  2826.   if (a != NULL && gdata != NULL) {
  2827.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2828.     *gp = *gdata;
  2829.     Nlm_HandUnlock (a);
  2830.     recentGraphic = a;
  2831.     recentGraphicData = *gdata;
  2832.   }
  2833. }
  2834.  
  2835. extern void Nlm_GetGraphicData (Nlm_GraphiC a, Nlm_GraphicData PNTR gdata)
  2836.  
  2837. {
  2838.   Nlm_GphPtr  gp;
  2839.  
  2840.   if (a != NULL && gdata != NULL) {
  2841.     if (a == recentGraphic && NLM_RISKY) {
  2842.       *gdata = recentGraphicData;
  2843.     } else {
  2844.       gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2845.       *gdata = *gp;
  2846.       Nlm_HandUnlock (a);
  2847.       recentGraphic = a;
  2848.       recentGraphicData = *gdata;
  2849.     }
  2850.   }
  2851. }
  2852.  
  2853. extern void Nlm_SetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata)
  2854.  
  2855. {
  2856.   Nlm_BoxPtr  bp;
  2857.  
  2858.   if (a != NULL && bdata != NULL) {
  2859.     bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2860.     bp->box = *bdata;
  2861.     Nlm_HandUnlock (a);
  2862.     recentBox = a;
  2863.     recentBoxData = *bdata;
  2864.   }
  2865. }
  2866.  
  2867. extern void Nlm_GetBoxData (Nlm_BoX a, Nlm_BoxData PNTR bdata)
  2868.  
  2869. {
  2870.   Nlm_BoxPtr  bp;
  2871.  
  2872.   if (a != NULL && bdata != NULL) {
  2873.     if (a == recentBox && NLM_RISKY) {
  2874.       *bdata = recentBoxData;
  2875.     } else {
  2876.       bp = (Nlm_BoxPtr) Nlm_HandLock (a);
  2877.       *bdata = bp->box;
  2878.       Nlm_HandUnlock (a);
  2879.       recentBox = a;
  2880.       recentBoxData = *bdata;
  2881.     }
  2882.   }
  2883. }
  2884.  
  2885. extern void Nlm_SetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr,
  2886.                               Nlm_Int2 start, Nlm_Int2 extra)
  2887.  
  2888. {
  2889.   Nlm_BytePtr  dst;
  2890.   Nlm_GphPtr   gp;
  2891.   Nlm_BytePtr  src;
  2892.  
  2893.   if (a != NULL && dptr != NULL) {
  2894.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2895.     dst = (Nlm_BytePtr) gp + start;
  2896.     src = (Nlm_BytePtr) dptr;
  2897.     while (extra > 0) {
  2898.       *dst = *src;
  2899.       dst++;
  2900.       src++;
  2901.       extra--;
  2902.     }
  2903.     Nlm_HandUnlock (a);
  2904.   }
  2905. }
  2906.  
  2907. extern void Nlm_GetExtraData (Nlm_GraphiC a, Nlm_VoidPtr dptr,
  2908.                               Nlm_Int2 start, Nlm_Int2 extra)
  2909.  
  2910. {
  2911.   Nlm_BytePtr  dst;
  2912.   Nlm_GphPtr   gp;
  2913.   Nlm_BytePtr  src;
  2914.  
  2915.   if (a != NULL && dptr != NULL) {
  2916.     gp = (Nlm_GphPtr) Nlm_HandLock (a);
  2917.     src = (Nlm_BytePtr) gp + start;
  2918.     dst = (Nlm_BytePtr) dptr;
  2919.     while (extra > 0) {
  2920.       *dst = *src;
  2921.       dst++;
  2922.       src++;
  2923.       extra--;
  2924.     }
  2925.     Nlm_HandUnlock (a);
  2926.   }
  2927. }
  2928.  
  2929. extern void Nlm_PointToolToPoinT (Nlm_PointTool src, Nlm_PointPtr dst)
  2930.  
  2931. {
  2932.   if (dst != NULL) {
  2933. #ifdef WIN_MAC
  2934.     dst->x = src.h;
  2935.     dst->y = src.v;
  2936. #endif
  2937. #ifdef WIN_MSWIN
  2938.     dst->x = (Nlm_Int2) src.x;
  2939.     dst->y = (Nlm_Int2) src.y;
  2940. #endif
  2941. #ifdef WIN_MOTIF
  2942.     dst->x = src.x;
  2943.     dst->y = src.y;
  2944. #endif
  2945.   }
  2946. }
  2947.  
  2948. extern void Nlm_PoinTToPointTool (Nlm_PoinT src, Nlm_PointTool PNTR dst)
  2949.  
  2950. {
  2951.   if (dst != NULL) {
  2952. #ifdef WIN_MAC
  2953.     dst->h = src.x;
  2954.     dst->v = src.y;
  2955. #endif
  2956. #ifdef WIN_MSWIN
  2957.     dst->x = src.x;
  2958.     dst->y = src.y;
  2959. #endif
  2960. #ifdef WIN_MOTIF
  2961.     dst->x = src.x;
  2962.     dst->y = src.y;
  2963. #endif
  2964.   }
  2965. }
  2966.  
  2967. extern void Nlm_RectToolToRecT (Nlm_RectTool PNTR src, Nlm_RectPtr dst)
  2968.  
  2969. {
  2970.   if (dst != NULL && src != NULL) {
  2971. #ifdef WIN_MAC
  2972.     dst->left = src->left;
  2973.     dst->top = src->top;
  2974.     dst->right = src->right;
  2975.     dst->bottom = src->bottom;
  2976. #endif
  2977. #ifdef WIN_MSWIN
  2978.     dst->left = (Nlm_Int2) src->left;
  2979.     dst->top = (Nlm_Int2) src->top;
  2980.     dst->right = (Nlm_Int2) src->right;
  2981.     dst->bottom = (Nlm_Int2) src->bottom;
  2982. #endif
  2983. #ifdef WIN_MOTIF
  2984.     dst->left = src->x;
  2985.     dst->top = src->y;
  2986.     dst->right = src->x + src->width;
  2987.     dst->bottom = src->y + src->height;
  2988. #endif
  2989.   }
  2990. }
  2991.  
  2992. extern void Nlm_RecTToRectTool (Nlm_RectPtr src, Nlm_RectTool PNTR dst)
  2993.  
  2994. {
  2995.   if (dst != NULL && src != NULL) {
  2996. #ifdef WIN_MAC
  2997.     dst->left = MIN (src->left, src->right);
  2998.     dst->top = MIN (src->top, src->bottom);
  2999.     dst->right = MAX (src->left, src->right);
  3000.     dst->bottom = MAX (src->top, src->bottom);
  3001. #endif
  3002. #ifdef WIN_MSWIN
  3003.     dst->left = MIN (src->left, src->right);
  3004.     dst->top = MIN (src->top, src->bottom);
  3005.     dst->right = MAX (src->left, src->right);
  3006.     dst->bottom = MAX (src->top, src->bottom);
  3007. #endif
  3008. #ifdef WIN_MOTIF
  3009.     dst->x = MIN (src->left, src->right);
  3010.     dst->y = MIN (src->top, src->bottom);
  3011.     dst->width = ABS (src->right - src->left);
  3012.     dst->height = ABS (src->bottom - src->top);
  3013. #endif
  3014.   }
  3015. }
  3016.  
  3017. extern void Nlm_LocalToGlobal (Nlm_PointPtr pt)
  3018.  
  3019. {
  3020. #ifdef WIN_MAC
  3021.   Nlm_PointTool  ptool;
  3022.  
  3023.   if (pt != NULL) {
  3024.     Nlm_PoinTToPointTool (*pt, &ptool);
  3025.     LocalToGlobal (&ptool);
  3026.     Nlm_PointToolToPoinT (ptool, pt);
  3027.   }
  3028. #endif
  3029. #ifdef WIN_MSWIN
  3030.   Nlm_PointTool  ptool;
  3031.  
  3032.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  3033.     Nlm_PoinTToPointTool (*pt, &ptool);
  3034.     ClientToScreen (Nlm_currentHWnd, &ptool);
  3035.     Nlm_PointToolToPoinT (ptool, pt);
  3036.   }
  3037. #endif
  3038. #ifdef WIN_MOTIF
  3039. #endif
  3040. }
  3041.  
  3042. extern void Nlm_GlobalToLocal (Nlm_PointPtr pt)
  3043.  
  3044. {
  3045. #ifdef WIN_MAC
  3046.   Nlm_PointTool  ptool;
  3047.  
  3048.   if (pt != NULL) {
  3049.     Nlm_PoinTToPointTool (*pt, &ptool);
  3050.     GlobalToLocal (&ptool);
  3051.     Nlm_PointToolToPoinT (ptool, pt);
  3052.   }
  3053. #endif
  3054. #ifdef WIN_MSWIN
  3055.   Nlm_PointTool  ptool;
  3056.  
  3057.   if (pt != NULL && Nlm_currentHWnd != NULL) {
  3058.     Nlm_PoinTToPointTool (*pt, &ptool);
  3059.     ScreenToClient (Nlm_currentHWnd, &ptool);
  3060.     Nlm_PointToolToPoinT (ptool, pt);
  3061.   }
  3062. #endif
  3063. #ifdef WIN_MOTIF
  3064. #endif
  3065. }
  3066.  
  3067. #ifdef OS_MAC
  3068. extern void Nlm_CtoPstr (Nlm_CharPtr str)
  3069.  
  3070. {
  3071. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3072.     c2pstr ((char *) str);
  3073. #else
  3074. #ifdef COMP_THINKC
  3075.     CtoPstr ((char *) str);
  3076. #endif
  3077. #endif
  3078. }
  3079.  
  3080. extern void Nlm_PtoCstr (Nlm_CharPtr str)
  3081.  
  3082. {
  3083. #if defined(COMP_MPW) || defined(COMP_CODEWAR)
  3084.   p2cstr ((StringPtr) str);
  3085. #else
  3086. #ifdef COMP_THINKC
  3087.   PtoCstr ((StringPtr) str);
  3088. #endif
  3089. #endif
  3090. }
  3091. #endif
  3092.  
  3093. #ifdef WIN_MSWIN
  3094. extern Nlm_Boolean Nlm_VibrantDisabled (void)
  3095.  
  3096. {
  3097.   if (Nlm_GetAppProperty("disable_vibrant") != NULL) {
  3098.     disabled_count++;
  3099.     return TRUE;
  3100.   }
  3101.   return FALSE;
  3102. }
  3103. #endif
  3104.  
  3105. #ifdef WIN_MSWIN
  3106. static void Nlm_SetupPrinterDeviceContext (HDC prHDC)
  3107.  
  3108. {
  3109.   HDC         screenDC;
  3110.   HWND        screenHwnd;
  3111.   /*
  3112.   TEXTMETRIC  textMetrics1;
  3113.   TEXTMETRIC  textMetrics2;
  3114.   */
  3115.  
  3116.   if (prHDC != NULL) {
  3117.     Nlm_SelectFont (Nlm_programFont);
  3118.     /*
  3119.     GetTextMetrics (Nlm_currentHDC, &textMetrics1);
  3120.     */
  3121.     Nlm_SetPort ((HWND) NULL, (HDC) prHDC);
  3122.     /*
  3123.     GetTextMetrics (prHDC, &textMetrics2);
  3124.     */
  3125.     SetMapMode (prHDC, MM_ANISOTROPIC);
  3126.     screenHwnd = GetDesktopWindow ();
  3127.     screenDC = GetDC (screenHwnd);
  3128.     SetWindowExtEx (prHDC, GetDeviceCaps (screenDC, LOGPIXELSX),
  3129.                     GetDeviceCaps (screenDC, LOGPIXELSY), NULL);
  3130.     SetViewportExtEx (prHDC, GetDeviceCaps (prHDC, LOGPIXELSX),
  3131.                       GetDeviceCaps (prHDC, LOGPIXELSY), NULL);
  3132.     ReleaseDC (screenHwnd, screenDC);
  3133.     /*
  3134.     SetWindowExtEx (prHDC, textMetrics1.tmAveCharWidth,
  3135.                     textMetrics1.tmHeight, NULL);
  3136.     SetViewportExtEx (prHDC, textMetrics2.tmAveCharWidth,
  3137.                     textMetrics2.tmHeight, NULL);
  3138.     */
  3139.   }
  3140. }
  3141. #endif
  3142.  
  3143. extern Nlm_WindoW Nlm_StartPrinting (void)
  3144.  
  3145. {
  3146.   Nlm_WindoW  w;
  3147. #ifdef WIN_MSWIN
  3148.   DWORD       commdlgerr;
  3149.   DOCINFO     di;
  3150.   char        docName [256];
  3151. #endif
  3152.  
  3153.   w = Nlm_CurrentWindow ();
  3154. #ifdef WIN_MAC
  3155.   PrOpen ();
  3156.   if (prHdl == NULL) {
  3157.     prHdl = (THPrint) Nlm_HandNew (sizeof (TPrint));
  3158.     if (prHdl != NULL) {
  3159.       PrintDefault (prHdl);
  3160.       prerr = PrError ();
  3161.       if (prerr != noErr) {
  3162.         Nlm_Message (MSG_ERROR, "PrintDefault error %d", prerr);
  3163.       }
  3164.       if (! PrStlDialog (prHdl)) {
  3165.         prHdl = (THPrint) Nlm_HandFree (prHdl);
  3166.         w = NULL;
  3167.       }
  3168.     } else {
  3169.       Nlm_Message (MSG_ERROR, "Unable to create print handle");
  3170.     }
  3171.   }
  3172.   if (prHdl != NULL) {
  3173.     if (PrJobDialog (prHdl)) {
  3174.       prPort = PrOpenDoc (prHdl, NULL, NULL);
  3175.       Nlm_SetPort ((GrafPtr) prPort);
  3176.       prerr = PrError ();
  3177.       if (prerr != noErr) {
  3178.         Nlm_Message (MSG_ERROR, "PrOpenDoc error %d", prerr);
  3179.       } else {
  3180.         Nlm_nowPrinting = TRUE;
  3181.       }
  3182.     } else {
  3183.       w = NULL;
  3184.     }
  3185.   } else {
  3186.     w = NULL;
  3187.   }
  3188. #endif
  3189. #ifdef WIN_MSWIN
  3190.   abortPrint = FALSE;
  3191.   memset (&pd, 0, sizeof (PRINTDLG));
  3192.   pd.lStructSize = sizeof (PRINTDLG);
  3193.   pd.hwndOwner = Nlm_currentHWnd;
  3194.   pd.Flags = PD_RETURNDC;
  3195.   if (PrintDlg (&pd) != 0) {
  3196.     hPr = pd.hDC;
  3197.     if (hPr != NULL) {
  3198.       Nlm_SetupPrinterDeviceContext (hPr);
  3199.       Nlm_StringCpy (docName, "Vibrant");
  3200.       di.cbSize = sizeof (DOCINFO);
  3201.       di.lpszDocName = (LPCSTR) docName;
  3202.       di.lpszOutput = NULL;
  3203.       prerr = StartDoc (hPr, &di);
  3204.       if (prerr < 1) {
  3205.         abortPrint = TRUE;
  3206.         Nlm_Message (MSG_ERROR, "StartDoc error %d", prerr);
  3207.         w = NULL;
  3208.       } else {
  3209.         Nlm_nowPrinting = TRUE;
  3210.       }
  3211.     } else {
  3212.       commdlgerr = CommDlgExtendedError ();
  3213.       Nlm_Message (MSG_ERROR, "Unable to create print context, error %ul", (long) commdlgerr);
  3214.       w = NULL;
  3215.     }
  3216.   } else {
  3217.     w = NULL;
  3218.   }
  3219. #endif
  3220. #ifdef WIN_MOTIF
  3221.   w = NULL;
  3222. #endif
  3223.   return w;
  3224. }
  3225.  
  3226. extern void Nlm_EndPrinting (Nlm_WindoW w)
  3227.  
  3228. {
  3229. #ifdef WIN_MAC
  3230.   TPrStatus  prStat;
  3231. #endif
  3232.  
  3233.   Nlm_nowPrinting = FALSE;
  3234. #ifdef WIN_MAC
  3235.   if (w != NULL) {
  3236.     PrCloseDoc (prPort);
  3237.     prerr = PrError ();
  3238.     if (prerr != noErr) {
  3239.       Nlm_Message (MSG_ERROR, "PrCloseDoc error %d", prerr);
  3240.     }
  3241.     PrPicFile (prHdl, 0L, 0L, 0L, &prStat);
  3242.     prerr = PrError ();
  3243.     if (prerr != noErr) {
  3244.       Nlm_Message (MSG_ERROR, "PrPicFile error %d", prerr);
  3245.     }
  3246.     prPort = NULL;
  3247.     Nlm_UseWindow (w);
  3248.   }
  3249.   PrClose ();
  3250. #endif
  3251. #ifdef WIN_MSWIN
  3252.   if (w != NULL) {
  3253.     if (hPr != NULL) {
  3254.       if (! abortPrint) {
  3255.         prerr = EndDoc (hPr);
  3256.         if (prerr < 0) {
  3257.           Nlm_Message (MSG_ERROR, "EndDoc error %d", prerr);
  3258.         }
  3259.       }
  3260.       DeleteDC (hPr);
  3261.       if (pd.hDevMode != NULL) {
  3262.         GlobalFree (pd.hDevMode);
  3263.       }
  3264.       if (pd.hDevNames != NULL) {
  3265.         GlobalFree (pd.hDevNames);
  3266.       }
  3267.     }
  3268.     Nlm_UseWindow (w);
  3269.   }
  3270. #endif
  3271. #ifdef WIN_MOTIF
  3272. #endif
  3273. }
  3274.  
  3275. extern Nlm_Boolean Nlm_PrintingRect (Nlm_RectPtr rpt)
  3276.  
  3277. {
  3278.   Nlm_Boolean   rsult;
  3279. #ifdef WIN_MAC
  3280.   TPPrint       prPtr;
  3281.   Nlm_RectTool  rtool;
  3282. #endif
  3283. #ifdef WIN_MSWIN
  3284.   POINT         physPageSize;
  3285.   POINT         pixelsPerInch;
  3286.   Nlm_PoinT     pt;
  3287. #endif
  3288.  
  3289.   rsult = TRUE;
  3290.   if (rpt != NULL) {
  3291.     Nlm_LoadRect (rpt, 0, 0, 0, 0);
  3292. #ifdef WIN_MAC
  3293.     if (prHdl != NULL) {
  3294.       prPtr = (TPPrint) Nlm_HandLock (prHdl);
  3295.       if (prPtr != NULL) {
  3296.         rtool = prPtr->prInfo.rPage;
  3297.         Nlm_RectToolToRecT (&rtool, rpt);
  3298.         Nlm_InsetRect (rpt, 10, 10);
  3299.       } else {
  3300.         rsult = FALSE;
  3301.       }
  3302.       Nlm_HandUnlock (prHdl);
  3303.     } else {
  3304.       rsult = FALSE;
  3305.     }
  3306. #endif
  3307. #ifdef WIN_MSWIN
  3308.     if (hPr != NULL) {
  3309.       physPageSize.x = GetDeviceCaps (hPr, HORZRES);
  3310.       physPageSize.y = GetDeviceCaps (hPr, VERTRES);
  3311.       DPtoLP (hPr, &physPageSize, 1);
  3312.       Nlm_PointToolToPoinT (physPageSize, &pt);
  3313.       rpt->right = pt.x;
  3314.       rpt->bottom = pt.y;
  3315.       pixelsPerInch.x = GetDeviceCaps (hPr, LOGPIXELSX);
  3316.       pixelsPerInch.y = GetDeviceCaps (hPr, LOGPIXELSY);
  3317.       DPtoLP (hPr, &pixelsPerInch, 1);
  3318.       Nlm_InsetRect (rpt, pixelsPerInch.x / 2, pixelsPerInch.y / 2);
  3319.     } else {
  3320.       rsult = FALSE;
  3321.     }
  3322. #endif
  3323. #ifdef WIN_MOTIF
  3324.     rsult = FALSE;
  3325. #endif
  3326.   }
  3327.   return rsult;
  3328. }
  3329.  
  3330. extern Nlm_Boolean Nlm_StartPage (void)
  3331.  
  3332. {
  3333.   Nlm_Boolean  rsult;
  3334.  
  3335.   rsult = TRUE;
  3336. #ifdef WIN_MAC
  3337.   if (prPort != NULL) {
  3338.     PrOpenPage (prPort, NULL);
  3339.     prerr = PrError ();
  3340.     if (prerr != noErr) {
  3341.       Nlm_Message (MSG_ERROR, "PrOpenPage error %d", prerr);
  3342.       rsult = FALSE;
  3343.     }
  3344.   } else {
  3345.     rsult = FALSE;
  3346.   }
  3347. #endif
  3348. #ifdef WIN_MSWIN
  3349.   if (hPr != NULL) {
  3350.     Nlm_SetupPrinterDeviceContext (hPr);
  3351.     prerr = StartPage (hPr);
  3352.     if (prerr < 0) {
  3353.       Nlm_Message (MSG_ERROR, "StartPage error %d", prerr);
  3354.       rsult = FALSE;
  3355.     }
  3356.     Nlm_SetPort ((HWND) NULL, (HDC) hPr);
  3357.   }
  3358. #endif
  3359. #ifdef WIN_MOTIF
  3360.   rsult = FALSE;
  3361. #endif
  3362.   return rsult;
  3363. }
  3364.  
  3365. extern Nlm_Boolean Nlm_EndPage (void)
  3366.  
  3367. {
  3368.   Nlm_Boolean  rsult;
  3369.  
  3370.   rsult = TRUE;
  3371. #ifdef WIN_MAC
  3372.   if (prPort != NULL) {
  3373.     PrClosePage (prPort);
  3374.     prerr = PrError ();
  3375.     if (prerr != noErr) {
  3376.       Nlm_Message (MSG_ERROR, "PrClosePage error %d", prerr);
  3377.       rsult = FALSE;
  3378.     }
  3379.   } else {
  3380.     rsult = FALSE;
  3381.   }
  3382. #endif
  3383. #ifdef WIN_MSWIN
  3384.   if (hPr != NULL) {
  3385.     prerr = EndPage (hPr);
  3386.     if (prerr < 0) {
  3387.       abortPrint = TRUE;
  3388.       Nlm_Message (MSG_ERROR, "EndPage error %d", prerr);
  3389.       rsult = FALSE;
  3390.     }
  3391.   } else {
  3392.     rsult = FALSE;
  3393.   }
  3394. #endif
  3395. #ifdef WIN_MOTIF
  3396.   rsult = FALSE;
  3397. #endif
  3398.   return rsult;
  3399. }
  3400.  
  3401. #ifdef WIN_MAC
  3402. static OSType Nlm_GetOSType (Nlm_CharPtr str, OSType dfault)
  3403.  
  3404. {
  3405.   OSType  rsult;
  3406.  
  3407.   rsult = dfault;
  3408.   if (str != NULL && str [0] != '\0') {
  3409.     rsult = *(OSType*) str;
  3410.   }
  3411.   return rsult;
  3412. }
  3413.  
  3414. static void Nlm_GetFilePath (Nlm_Int2 currentVol, Nlm_CharPtr path, Nlm_sizeT maxsize)
  3415.  
  3416. {
  3417.   WDPBRec     block;
  3418.   Nlm_Char    directory [256];
  3419.   Nlm_Int4    dirID;
  3420.   OSErr       err;
  3421.   CInfoPBRec  params;
  3422.   Nlm_Char    temp [256];
  3423.   Nlm_Int2    vRefNum;
  3424.  
  3425.   block.ioNamePtr = NULL;
  3426.   block.ioVRefNum = currentVol;
  3427.   block.ioWDIndex = 0;
  3428.   block.ioWDProcID = 0;
  3429.   PBGetWDInfo (&block, FALSE);
  3430.   dirID = block.ioWDDirID;
  3431.   vRefNum = block.ioWDVRefNum;
  3432.   temp [0] = '\0';
  3433.   params.dirInfo.ioNamePtr = (StringPtr) directory;
  3434.   params.dirInfo.ioDrParID = dirID;
  3435.   do {
  3436.     params.dirInfo.ioVRefNum = vRefNum;
  3437.     params.dirInfo.ioFDirIndex = -1;
  3438.     params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID;
  3439.     err = PBGetCatInfo (¶ms, FALSE);
  3440.     Nlm_PtoCstr (directory);
  3441.     Nlm_StrngCat (directory, ":", sizeof (directory));
  3442.     Nlm_StrngCat (directory, temp, sizeof (directory));
  3443.     Nlm_StrngCpy (temp, directory, sizeof (temp));
  3444.   } while (params.dirInfo.ioDrDirID != fsRtDirID);
  3445.   Nlm_StringNCpy (path, temp, maxsize);
  3446. }
  3447. #endif
  3448.  
  3449. #ifdef WIN_MOTIF
  3450. static void Nlm_CreateFileDialogShell (void)
  3451.  
  3452. {
  3453.   Cardinal  n;
  3454.   Arg       wargs [15];
  3455.  
  3456.   if (Nlm_fileDialogShell == NULL) {
  3457.     n = 0;
  3458.     XtSetArg (wargs[n], XmNdefaultFontList, Nlm_XfontList); n++;
  3459.     XtSetArg (wargs[n], XmNdeleteResponse, XmDO_NOTHING); n++;
  3460.     Nlm_fileDialogShell = XtAppCreateShell ((String) NULL, (String) "Vibrant",
  3461.                                             applicationShellWidgetClass,
  3462.                                             Nlm_currentXDisplay, wargs, n);
  3463.   }
  3464. }
  3465.  
  3466. static void Nlm_FileCancelCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3467.  
  3468. {
  3469.   fileBoxUp = FALSE;
  3470.   fileBoxRsult = FALSE;
  3471. }
  3472.  
  3473. static void Nlm_FileOkCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3474.  
  3475. {
  3476.   XmFileSelectionBoxCallbackStruct  *cbs;
  3477.   char                              *filename;
  3478.  
  3479.   cbs = (XmFileSelectionBoxCallbackStruct *) call_data;
  3480.   fileBoxUp = FALSE;
  3481.   if (! XmStringGetLtoR (cbs->value, XmSTRING_DEFAULT_CHARSET, &filename)) {
  3482.     return;
  3483.   }
  3484.   if (! *filename) {
  3485.     XtFree (filename);
  3486.     return;
  3487.   }
  3488.   Nlm_StringNCpy (filePath, filename, sizeof (filePath));
  3489.   XtFree (filename);
  3490.   fileBoxRsult = TRUE;
  3491. }
  3492.  
  3493. static void Nlm_FileNoMatchCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3494.  
  3495. {
  3496.   fileBoxUp = FALSE;
  3497.   fileBoxRsult = FALSE;
  3498. }
  3499.  
  3500. static void Nlm_FileMapCallback (Widget fs, XtPointer client_data, XtPointer call_data)
  3501.  
  3502. {
  3503.   Position   x, y;
  3504.   Dimension  w, h;
  3505.  
  3506.   XtVaGetValues (fs, XmNwidth, &w, XmNheight, &h, NULL);
  3507.   x = (Position) (Nlm_screenRect.right - w) / (Position) 2;
  3508.   y = (Position) (Nlm_screenRect.bottom - h) / (Position) 3;
  3509.   XtVaSetValues (fs, XmNx, x, XmNy, y, NULL);
  3510. }
  3511. #endif
  3512.  
  3513. extern Nlm_Boolean Nlm_GetInputFileName (Nlm_CharPtr fileName, Nlm_sizeT maxsize,
  3514.                                          Nlm_CharPtr extType, Nlm_CharPtr macType)
  3515.  
  3516. {
  3517. #ifdef WIN_MAC
  3518.   Nlm_Char       currentFileName [64];
  3519.   Nlm_Char       currentPath [256];
  3520.   SFTypeList     fTypeList;
  3521.   Nlm_Int2       i;
  3522.   Nlm_Int2       lengthTypes;
  3523.   Nlm_Int2       numTypes;
  3524.   Nlm_PointTool  ptool;
  3525.   Nlm_RecT       r;
  3526.   SFReply        reply;
  3527.   Nlm_Boolean    rsult;
  3528.   Nlm_RectTool   rtool;
  3529.   GrafPtr        tempPort;
  3530.   PenState       state;
  3531.   Nlm_Char       str [5];
  3532.   Nlm_PoinT      where;
  3533.  
  3534.   where.x = 90;
  3535.   where.y = 100;
  3536.   lengthTypes = sizeof (fileTypes);
  3537.   for (i = 0; i < lengthTypes; i++) {
  3538.     fileTypes [i] = '\0';
  3539.   }
  3540. #ifdef DCLAP
  3541.     /* allow several types in this list! */
  3542.   if (macType != NULL && macType [0] != '\0') {
  3543.     Nlm_StringNCpy (fileTypes, macType, lengthTypes);
  3544.     /*fileTypes [lengthTypes-1] = '\0';*/
  3545.   }
  3546. #else
  3547.   if (macType != NULL && macType [0] != '\0') {
  3548.     Nlm_StringNCpy (fileTypes, macType, 6);
  3549.     fileTypes [4] = '\0';
  3550.   }
  3551. #endif
  3552.   if (fileTypes [0] != '\0') {
  3553.     numTypes = 0;
  3554.     i = 0;
  3555.     while (numTypes < 4 && i < lengthTypes) {
  3556.       Nlm_StrngSeg (str, fileTypes, i, 4, sizeof (str));
  3557.       fTypeList [numTypes] = Nlm_GetOSType (str, '    ');
  3558.       numTypes++;
  3559.       i += 4;
  3560.     }
  3561.   } else {
  3562.     numTypes = -1;
  3563.   }
  3564.   GetPenState (&state);
  3565.   GetPort (&tempPort);
  3566.   Nlm_PoinTToPointTool (where, &ptool);
  3567.   SFGetFile (ptool, NULL, NULL, numTypes, fTypeList, NULL, &reply);
  3568.   SetPort (tempPort);
  3569.   SetPenState (&state);
  3570.   Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r);
  3571.   Nlm_RecTToRectTool (&r, &rtool);
  3572.   ClipRect (&rtool);
  3573.   if (reply.good != 0 && fileName != NULL) {
  3574.     Nlm_StringNCpy (currentFileName, (Nlm_CharPtr) &(reply.fName),
  3575.                     sizeof (currentFileName));
  3576.     Nlm_PtoCstr (currentFileName);
  3577.     Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath));
  3578.     Nlm_StringNCat (currentPath, currentFileName,
  3579.                     sizeof (currentPath) - Nlm_StringLen (currentPath));
  3580.     Nlm_StringNCpy (fileName, currentPath, maxsize);
  3581.     rsult = TRUE;
  3582.   } else {
  3583.     rsult = FALSE;
  3584.   }
  3585.   Nlm_Update ();
  3586.   return rsult;
  3587. #endif
  3588. #ifdef WIN_MSWIN
  3589.   char  szDirName [256];
  3590.   char  szFile [256];
  3591.   char  szFileTitle [256];
  3592.   UINT  i;
  3593.   UINT  cbString;
  3594.   char  chReplace;
  3595.   char  szFilter [256];
  3596.   char  *lastSlash;
  3597.  
  3598.   GetModuleFileName (Nlm_currentHInst, szDirName, sizeof (szDirName));
  3599.   lastSlash = strrchr (szDirName, DIRDELIMCHR);
  3600.   if (lastSlash != NULL) {
  3601.     lastSlash [1] = '\0';
  3602.   }
  3603.   szFile [0] = '\0';
  3604.   if (extType != NULL && extType [0] != '\0') {
  3605.     Nlm_StringCpy (szFilter, "Filtered Files (*");
  3606.     if (extType [0] != '.') {
  3607.       Nlm_StringCat (szFilter, ".");
  3608.     }
  3609.     Nlm_StringNCat (szFilter, extType, 5);
  3610.     Nlm_StringCat (szFilter, ")|*");
  3611.     if (extType [0] != '.') {
  3612.       Nlm_StringCat (szFilter, ".");
  3613.     }
  3614.     Nlm_StringNCat (szFilter, extType, 5);
  3615.     Nlm_StringCat (szFilter, "|");
  3616.   } else {
  3617.     Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|");
  3618.   }
  3619.   cbString = (UINT) Nlm_StringLen (szFilter);
  3620.   chReplace = szFilter [cbString - 1];
  3621.   for (i = 0; szFilter [i] != '\0'; i++) {
  3622.     if (szFilter [i] == chReplace) {
  3623.       szFilter [i] = '\0';
  3624.     }
  3625.   }
  3626.   memset (&ofn, 0, sizeof (OPENFILENAME));
  3627.   ofn.lStructSize = sizeof (OPENFILENAME);
  3628.   ofn.hwndOwner = Nlm_currentHWnd;
  3629.   ofn.lpstrFilter = szFilter;
  3630.   ofn.nFilterIndex = 1;
  3631.   ofn.lpstrFile = szFile;
  3632.   ofn.nMaxFile = sizeof (szFile);
  3633.   ofn.lpstrFileTitle = szFileTitle;
  3634.   ofn.nMaxFileTitle = sizeof (szFileTitle);
  3635.   ofn.lpstrInitialDir = szDirName;
  3636.   ofn.Flags = OFN_SHOWHELP | OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
  3637.   if (GetOpenFileName (&ofn) && fileName != NULL) {
  3638.     Nlm_StringNCpy (fileName, ofn.lpstrFile, maxsize);
  3639.     AnsiToOemBuff (fileName, fileName, maxsize);
  3640.     return TRUE;
  3641.   } else {
  3642.     return FALSE;
  3643.   }
  3644. #endif
  3645. #ifdef WIN_MOTIF
  3646.   XmString  dirmask;
  3647.   char      *lastSlash;
  3648.   char      str [256];
  3649.   char      *text;
  3650.   Widget    txt;
  3651.  
  3652.   Nlm_CreateFileDialogShell ();
  3653.   if (Nlm_fileDialogShell != NULL && fileName != NULL) {
  3654.     if (fileDialog == NULL) {
  3655.       fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell,
  3656.                                                 (String) "file_selection", NULL, 0);
  3657.       XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL);
  3658.       XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL);
  3659.       XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL);
  3660.       XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL);
  3661.       XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE,
  3662.                      XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
  3663.     }
  3664.     if (fileDialog != NULL) {
  3665.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT);
  3666.       text = XmTextGetString (txt);
  3667.       Nlm_StringNCpy (str, text, sizeof (str) - 1);
  3668.       lastSlash = Nlm_StringRChr (str, DIRDELIMCHR);
  3669.       if (lastSlash != NULL) {
  3670.         lastSlash [1] = '\0';
  3671.       } else {
  3672.         lastSlash = &(str [Nlm_StringLen (str) - 1]);
  3673.       }
  3674.       if (extType != NULL && extType [0] != '\0') {
  3675.         Nlm_StringCat (str, "*");
  3676.         if (extType [0] != '.') {
  3677.           Nlm_StringCat (str, ".");
  3678.         }
  3679.         Nlm_StringNCat (str, extType, 5);
  3680.         dirmask = XmStringCreateLtoR (str, XmSTRING_DEFAULT_CHARSET);
  3681.         XmFileSelectionDoSearch (fileDialog, dirmask);
  3682.         XmStringFree (dirmask);
  3683.         if (lastSlash != NULL) {
  3684.           lastSlash [1] = '\0';
  3685.         }
  3686.       }
  3687.       XtFree (text);
  3688.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT);
  3689.       XmTextSetString (txt, str);
  3690.       XtVaSetValues (fileDialog, XmNmustMatch, TRUE, NULL);
  3691.       fileBoxUp = TRUE;
  3692.       fileBoxRsult = FALSE;
  3693.       XtManageChild (fileDialog);
  3694.       XSync (Nlm_currentXDisplay, FALSE);
  3695.       while (fileBoxUp) {
  3696.         Nlm_ProcessAnEvent ();
  3697.       }
  3698.       if (fileBoxRsult) {
  3699.         Nlm_StringNCpy (fileName, filePath, maxsize);
  3700.       }
  3701.       XtUnmanageChild (fileDialog);
  3702.       XSync (Nlm_currentXDisplay, FALSE);
  3703.     }
  3704.   }
  3705.   return fileBoxRsult;
  3706. #endif
  3707. }
  3708.  
  3709. #ifdef WIN_MSWIN
  3710. static void Nlm_CopyDefaultName (Nlm_CharPtr dst, Nlm_CharPtr src)
  3711.  
  3712. {
  3713.   Nlm_Char  ch;
  3714.   Nlm_Int2  i;
  3715.   Nlm_Int2  j;
  3716.   Nlm_Int2  k;
  3717.  
  3718.   if (dst != NULL && src != NULL) {
  3719.     i = 0;
  3720.     j = 0;
  3721.     k = 0;
  3722.     ch = src [i];
  3723.     while (k < 8 && ch != '\0' && IS_ALPHANUM (ch)) {
  3724.       dst [j] = ch;
  3725.       i++;
  3726.       j++;
  3727.       k++;
  3728.       ch = src [i];
  3729.     }
  3730.     while (ch != '\0' && ch != '.') {
  3731.       i++;
  3732.       ch = src [i];
  3733.     }
  3734.     if (ch == '.') {
  3735.       dst [j] = ch;
  3736.       i++;
  3737.       j++;
  3738.       ch = src [i];
  3739.       k = 0;
  3740.       while (k < 3 && ch != '\0' && IS_ALPHANUM (ch)) {
  3741.         dst [j] = ch;
  3742.         i++;
  3743.         j++;
  3744.         k++;
  3745.         ch = src [i];
  3746.       }
  3747.     }
  3748.     dst [j] = '\0';
  3749.   }
  3750. }
  3751. #endif
  3752.  
  3753. extern Nlm_Boolean Nlm_GetOutputFileName (Nlm_CharPtr fileName, Nlm_sizeT maxsize,
  3754.                                           Nlm_CharPtr dfault)
  3755.  
  3756. {
  3757. #ifdef WIN_MAC
  3758.   Nlm_Char       currentFileName [64];
  3759.   Nlm_Char       currentPath [256];
  3760.   unsigned char  original [256];
  3761.   unsigned char  promptStr [256];
  3762.   Nlm_PointTool  ptool;
  3763.   Nlm_RecT       r;
  3764.   SFReply        reply;
  3765.   Nlm_Boolean    rsult;
  3766.   Nlm_RectTool   rtool;
  3767.   GrafPtr        tempPort;
  3768.   PenState       state;
  3769.   Nlm_PoinT      where;
  3770.  
  3771.   where.x = 90;
  3772.   where.y = 100;
  3773.   GetPenState (&state);
  3774.   GetPort (&tempPort);
  3775.   Nlm_PoinTToPointTool (where, &ptool);
  3776.   original [0] = '\0';
  3777.   Nlm_StringNCpy ((Nlm_CharPtr) original, dfault, sizeof (original));
  3778.   Nlm_CtoPstr ((Nlm_CharPtr) original);
  3779.   Nlm_StringNCpy ((Nlm_CharPtr) promptStr, "Save File As:", sizeof (promptStr));
  3780.   Nlm_CtoPstr ((Nlm_CharPtr) promptStr);
  3781.   SFPutFile (ptool, promptStr, original, NULL, &reply);
  3782.   SetPort (tempPort);
  3783.   SetPenState (&state);
  3784.   Nlm_GetRect ((Nlm_GraphiC) Nlm_desktopWindow, &r);
  3785.   Nlm_RecTToRectTool (&r, &rtool);
  3786.   ClipRect (&rtool);
  3787.   if (reply.good != 0 && fileName != NULL) {
  3788.     Nlm_StringNCpy (currentFileName, (Nlm_CharPtr) &(reply.fName),
  3789.                     sizeof (currentFileName));
  3790.     Nlm_PtoCstr (currentFileName);
  3791.     Nlm_GetFilePath (reply.vRefNum, currentPath, sizeof (currentPath));
  3792.     Nlm_StringNCat (currentPath, currentFileName,
  3793.                     sizeof (currentPath) - Nlm_StringLen (currentPath));
  3794.     Nlm_StringNCpy (fileName, currentPath, maxsize);
  3795.     rsult = TRUE;
  3796.   } else {
  3797.     rsult = FALSE;
  3798.   }
  3799.   Nlm_Update ();
  3800.   return rsult;
  3801. #endif
  3802. #ifdef WIN_MSWIN
  3803.   FILE  *f;
  3804.   char  szDirName [256];
  3805.   char  szFile [256];
  3806.   char  szFileTitle [256];
  3807.   UINT  i;
  3808.   UINT  cbString;
  3809.   char  chReplace;
  3810.   char  szFilter [256];
  3811.   char  *lastSlash;
  3812.  
  3813.   GetModuleFileName (Nlm_currentHInst, szDirName, sizeof (szDirName));
  3814.   lastSlash = strrchr (szDirName, DIRDELIMCHR);
  3815.   if (lastSlash != NULL) {
  3816.     lastSlash [1] = '\0';
  3817.   }
  3818.   szFile [0] = '\0';
  3819.   Nlm_CopyDefaultName ((Nlm_CharPtr) szFile, dfault);
  3820.   Nlm_StringCpy (szFilter, "All Files (*.*)|*.*|");
  3821.   cbString = (UINT) Nlm_StringLen (szFilter);
  3822.   chReplace = szFilter [cbString - 1];
  3823.   for (i = 0; szFilter [i] != '\0'; i++) {
  3824.     if (szFilter [i] == chReplace) {
  3825.       szFilter [i] = '\0';
  3826.     }
  3827.   }
  3828.   memset (&ofn, 0, sizeof (OPENFILENAME));
  3829.   ofn.lStructSize = sizeof (OPENFILENAME);
  3830.   ofn.hwndOwner = Nlm_currentHWnd;
  3831.   ofn.lpstrFilter = szFilter;
  3832.   ofn.lpstrFile = szFile;
  3833.   ofn.nMaxFile = sizeof (szFile);
  3834.   ofn.lpstrFileTitle = szFileTitle;
  3835.   ofn.nMaxFileTitle = sizeof (szFileTitle);
  3836.   ofn.lpstrInitialDir = szDirName;
  3837.   /*
  3838.   ofn.Flags = OFN_SHOWHELP | OFN_OVERWRITEPROMPT;
  3839.   */
  3840.   /* OFN_OVERWRITEPROMPT causes crashes for some unknown reason */
  3841.   ofn.Flags = OFN_SHOWHELP;
  3842.   if (GetSaveFileName (&ofn) && fileName != NULL) {
  3843.     Nlm_StringNCpy (fileName, ofn.lpstrFile, maxsize);
  3844.     AnsiToOemBuff (fileName, fileName, maxsize);
  3845.     f = Nlm_FileOpen (fileName, "r");
  3846.     if (f != NULL) {
  3847.       Nlm_FileClose (f);
  3848.       if (Nlm_Message (MSG_YN, "Replace existing file?") == ANS_NO) {
  3849.         return FALSE;
  3850.       }
  3851.     }
  3852.     return TRUE;
  3853.   } else {
  3854.     return FALSE;
  3855.   }
  3856. #endif
  3857. #ifdef WIN_MOTIF
  3858.   char   *lastSlash;
  3859.   char    str [256];
  3860.   char    *text;
  3861.   Widget  txt;
  3862.  
  3863.   Nlm_CreateFileDialogShell ();
  3864.   if (Nlm_fileDialogShell != NULL && fileName != NULL) {
  3865.     if (fileDialog == NULL) {
  3866.       fileDialog = XmCreateFileSelectionDialog (Nlm_fileDialogShell,
  3867.                                                 (String) "file_selection", NULL, 0);
  3868.       XtAddCallback (fileDialog, XmNcancelCallback, Nlm_FileCancelCallback, NULL);
  3869.       XtAddCallback (fileDialog, XmNokCallback, Nlm_FileOkCallback, NULL);
  3870.       XtAddCallback (fileDialog, XmNnoMatchCallback, Nlm_FileNoMatchCallback, NULL);
  3871.       XtAddCallback (fileDialog, XmNmapCallback, Nlm_FileMapCallback, NULL);
  3872.       XtVaSetValues (fileDialog, XmNdefaultPosition, FALSE,
  3873.                      XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL, NULL);
  3874.     }
  3875.     if (fileDialog != NULL) {
  3876.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_FILTER_TEXT);
  3877.       text = XmTextGetString (txt);
  3878.       Nlm_StringNCpy (str, text, sizeof (str) - 1);
  3879.       lastSlash = Nlm_StringRChr (str, DIRDELIMCHR);
  3880.       if (lastSlash != NULL) {
  3881.         lastSlash [1] = '\0';
  3882.       }
  3883.       XtFree (text);
  3884.       if (dfault != NULL) {
  3885.         Nlm_StringNCat (str, dfault, sizeof (str) - Nlm_StringLen (str));
  3886.       }
  3887.       txt = XmFileSelectionBoxGetChild (fileDialog, XmDIALOG_TEXT);
  3888.       XmTextSetString (txt, str);
  3889.       XtVaSetValues (fileDialog, XmNmustMatch, FALSE, NULL);
  3890.       fileBoxUp = TRUE;
  3891.       fileBoxRsult = FALSE;
  3892.       XtManageChild (fileDialog);
  3893.       while (fileBoxUp) {
  3894.         Nlm_ProcessAnEvent ();
  3895.       }
  3896.       if (fileBoxRsult) {
  3897.         Nlm_StringNCpy (fileName, filePath, maxsize);
  3898.       }
  3899.       XtUnmanageChild (fileDialog);
  3900.     }
  3901.   }
  3902.   return fileBoxRsult;
  3903. #endif
  3904. }
  3905.  
  3906. extern Nlm_Boolean Nlm_LaunchApp (Nlm_CharPtr fileName)
  3907.  
  3908. {
  3909. #ifdef WIN_MAC
  3910.   OSErr                err;
  3911.   FSSpec               fsspec;
  3912.   long                 gval;
  3913.   LaunchParamBlockRec  myLaunchParams;
  3914.   unsigned char        pathname [256];
  3915.   Nlm_CharPtr          ptr;
  3916.   Nlm_Boolean          rsult;
  3917.  
  3918.   rsult = FALSE;
  3919.   if (Gestalt (gestaltSystemVersion, &gval) == noErr && (short) gval >= 7 * 256) {
  3920.     if (fileName != NULL && fileName [0] != '\0') {
  3921.       if (Nlm_StringChr (fileName, DIRDELIMCHR) != NULL) {
  3922.         Nlm_StringNCpy ((Nlm_CharPtr) pathname, fileName, sizeof (pathname));
  3923.       } else {
  3924.         Nlm_ProgramPath ((Nlm_CharPtr) pathname, sizeof (pathname));
  3925.         ptr = Nlm_StringRChr ((Nlm_CharPtr) pathname, DIRDELIMCHR);
  3926.         if (ptr != NULL) {
  3927.           *ptr = '\0';
  3928.         }
  3929.         Nlm_FileBuildPath ((Nlm_CharPtr) pathname, NULL, fileName);
  3930.       }
  3931.       Nlm_CtoPstr ((Nlm_CharPtr) pathname);
  3932.       err = FSMakeFSSpec (0, 0, pathname, &(fsspec));
  3933.       myLaunchParams.launchBlockID = extendedBlock;
  3934.       myLaunchParams.launchEPBLength = extendedBlockLen;
  3935.       myLaunchParams.launchFileFlags = 0;
  3936.       myLaunchParams.launchControlFlags = launchContinue + launchNoFileFlags;
  3937.       myLaunchParams.launchAppParameters = NULL;
  3938.       myLaunchParams.launchAppSpec = &fsspec;
  3939.       rsult = (Nlm_Boolean) (LaunchApplication (&myLaunchParams) == noErr);
  3940.     }
  3941.   }
  3942.   return rsult;
  3943. #endif
  3944. #ifdef WIN_MSWIN
  3945.   Nlm_Char     ch;
  3946.   Nlm_Int2     i;
  3947.   Nlm_Int2     j;
  3948.   Nlm_Int2     k;
  3949.   char         lpszCmdLine [256];
  3950.   Nlm_Boolean  rsult;
  3951.  
  3952.   rsult = FALSE;
  3953.   if (fileName != NULL && fileName [0] != '\0') {
  3954.     Nlm_StringNCpy ((Nlm_CharPtr) lpszCmdLine, fileName, sizeof (lpszCmdLine));
  3955.     i = 0;
  3956.     j = 0;
  3957.     k = 0;
  3958.     ch = fileName [j];
  3959.     while (i < 8 && ch != '\0') {
  3960.       if (ch == '_' || IS_ALPHANUM (ch)) {
  3961.         lpszCmdLine [k] = ch;
  3962.         j++;
  3963.         k++;
  3964.         ch = fileName [j];
  3965.       }
  3966.       i++;
  3967.     }
  3968.     while (ch != '\0' && ch != '.') {
  3969.       j++;
  3970.       ch = fileName [j];
  3971.     }
  3972.     if (ch == '.') {
  3973.       lpszCmdLine [k] = ch;
  3974.       j++;
  3975.       k++;
  3976.       ch = fileName [j];
  3977.       i = 0;
  3978.       while (i < 3 && ch != '\0') {
  3979.         if (ch == '_' || IS_ALPHANUM (ch)) {
  3980.           lpszCmdLine [k] = ch;
  3981.           j++;
  3982.           k++;
  3983.           ch = fileName [j];
  3984.         }
  3985.         i++;
  3986.       }
  3987.     }
  3988.     if (k > 0 && lpszCmdLine [k - 1] == '.') {
  3989.       lpszCmdLine [k - 1] = '\0';
  3990.     }
  3991.     lpszCmdLine [k] = '\0';
  3992.     rsult = (Nlm_Boolean) (WinExec (lpszCmdLine, SW_SHOW) >= 32);
  3993.   }
  3994.   return rsult;
  3995. #endif
  3996. #ifdef WIN_MOTIF
  3997.   Nlm_Boolean  rsult;
  3998.   int          status;
  3999.  
  4000.   rsult = FALSE;
  4001.   if (fileName != NULL && fileName [0] != '\0') {
  4002. #ifdef OS_UNIX
  4003.     status = (int) fork ();
  4004.     if (status == 0) {
  4005.       execl (fileName, fileName, (char *) 0);
  4006.       Nlm_Message (MSG_FATAL, "Application launch failed");
  4007.     } else if (status != -1) {
  4008.       rsult = TRUE;
  4009.     }
  4010. #endif
  4011. #ifdef OS_VMS
  4012.     status = execl (fileName, fileName, (char *) 0);
  4013.     if ( status == -1 ) {
  4014.       Nlm_Message (MSG_FATAL, "Application launch failed");
  4015.     } else {
  4016.       rsult = TRUE;
  4017.     }
  4018. #endif
  4019.   }
  4020.   return rsult;
  4021. #endif
  4022. }
  4023.  
  4024. /* ++dgg -- added by d.gilbert, dec'93, for use w/ DCLAP c++ library */
  4025.  
  4026. extern void Nlm_SetObject (Nlm_GraphiC a, Nlm_VoidPtr thisobject)
  4027. {
  4028.   Nlm_GraphicData  gdata;
  4029.   if (a != NULL) { /* dgg - removed test for thisobject != NULL -- need to set null */
  4030.     Nlm_GetGraphicData (a, &gdata);
  4031.     gdata.thisobject = thisobject;
  4032.     Nlm_SetGraphicData (a, &gdata);
  4033.   }
  4034. }
  4035.  
  4036. extern Nlm_VoidPtr Nlm_GetObject (Nlm_GraphiC a)
  4037. {
  4038.   Nlm_GraphicData  gdata;
  4039.   if (a != NULL) {
  4040.     Nlm_GetGraphicData (a, &gdata);
  4041.     return gdata.thisobject;
  4042.   } else {
  4043.     return NULL;
  4044.   }
  4045. }
  4046.  
  4047.